2018-09-12 11:35:51 +01:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using System;
|
2018-08-28 18:30:58 +01:00
|
|
|
|
using System.Collections.Generic;
|
2018-09-03 21:29:13 +01:00
|
|
|
|
using System.Web.Http;
|
2018-08-27 20:05:59 +01:00
|
|
|
|
using Umbraco.Core.Logging.Viewer;
|
2018-08-28 18:30:58 +01:00
|
|
|
|
using Umbraco.Core.Models;
|
2018-08-30 14:27:31 +01:00
|
|
|
|
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
2018-08-27 20:05:59 +01:00
|
|
|
|
using Umbraco.Web.Mvc;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Editors
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2018-08-28 14:48:54 +01:00
|
|
|
|
/// Backoffice controller supporting the dashboard for viewing logs with some simple graphs & filtering
|
2018-08-27 20:05:59 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
[PluginController("UmbracoApi")]
|
2018-08-29 18:42:12 +01:00
|
|
|
|
public class LogViewerController : UmbracoAuthorizedJsonController
|
2018-08-27 20:05:59 +01:00
|
|
|
|
{
|
2018-08-28 14:48:54 +01:00
|
|
|
|
private ILogViewer _logViewer;
|
2018-08-27 20:05:59 +01:00
|
|
|
|
|
2018-08-29 18:42:12 +01:00
|
|
|
|
public LogViewerController(ILogViewer logViewer)
|
2018-08-27 20:05:59 +01:00
|
|
|
|
{
|
2018-08-28 14:48:54 +01:00
|
|
|
|
_logViewer = logViewer;
|
2018-08-27 20:05:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public int GetNumberOfErrors()
|
|
|
|
|
|
{
|
2018-09-03 21:29:13 +01:00
|
|
|
|
return _logViewer.GetNumberOfErrors(startDate: DateTime.Now.AddDays(-1), endDate: DateTime.Now);
|
2018-08-27 20:05:59 +01:00
|
|
|
|
}
|
2018-08-28 14:48:54 +01:00
|
|
|
|
|
2018-08-27 20:05:59 +01:00
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public LogLevelCounts GetLogLevelCounts()
|
|
|
|
|
|
{
|
2018-09-03 21:29:13 +01:00
|
|
|
|
return _logViewer.GetLogLevelCounts(startDate: DateTime.Now.AddDays(-1), endDate: DateTime.Now);
|
2018-08-27 20:05:59 +01:00
|
|
|
|
}
|
2018-08-28 14:48:54 +01:00
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2018-09-07 21:43:44 +01:00
|
|
|
|
public IEnumerable<LogTemplate> GetMessageTemplates()
|
2018-08-28 14:48:54 +01:00
|
|
|
|
{
|
2018-09-07 21:43:44 +01:00
|
|
|
|
return _logViewer.GetMessageTemplates(startDate: DateTime.Now.AddDays(-1), endDate: DateTime.Now);
|
2018-08-28 14:48:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2018-09-03 21:29:13 +01:00
|
|
|
|
public PagedResult<LogMessage> GetLogs(string orderDirection = "Descending", int pageNumber = 1, string filterExpression = null, [FromUri]string[] logLevels = null)
|
2018-08-28 14:48:54 +01:00
|
|
|
|
{
|
2018-08-30 14:27:31 +01:00
|
|
|
|
var direction = orderDirection == "Descending" ? Direction.Descending : Direction.Ascending;
|
2018-09-03 21:29:13 +01:00
|
|
|
|
return _logViewer.GetLogs(startDate: DateTime.Now.AddDays(-1), endDate: DateTime.Now, filterExpression: filterExpression, pageNumber: pageNumber, orderDirection: direction, logLevels: logLevels);
|
2018-08-28 14:48:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-12 11:35:51 +01:00
|
|
|
|
[HttpGet]
|
|
|
|
|
|
public IEnumerable<SavedLogSearch> GetSavedSearches()
|
|
|
|
|
|
{
|
|
|
|
|
|
return _logViewer.GetSavedSearches();
|
|
|
|
|
|
}
|
2018-08-27 20:05:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|