Files
Umbraco-CMS/src/Umbraco.Web/Editors/LogViewerController.cs

109 lines
3.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Web.Http;
using Umbraco.Core.Logging.Viewer;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
using Umbraco.Web.Mvc;
2018-11-02 11:09:59 +00:00
using Umbraco.Web.WebApi;
namespace Umbraco.Web.Editors
{
/// <summary>
/// Backoffice controller supporting the dashboard for viewing logs with some simple graphs & filtering
/// </summary>
[PluginController("UmbracoApi")]
public class LogViewerController : UmbracoAuthorizedJsonController
{
private ILogViewer _logViewer;
public LogViewerController(ILogViewer logViewer)
{
_logViewer = logViewer;
}
private bool CanViewLogs()
{
2018-11-02 11:09:59 +00:00
//Can the interface deal with Large Files
if (_logViewer.CanHandleLargeLogs)
return true;
2018-11-02 11:09:59 +00:00
//Interface CheckCanOpenLogs
return _logViewer.CheckCanOpenLogs(startDate: DateTime.Now.AddDays(-1), endDate: DateTime.Now);
}
[HttpGet]
2018-11-02 11:09:59 +00:00
public bool GetCanViewLogs()
{
2018-11-02 11:09:59 +00:00
return CanViewLogs();
}
[HttpGet]
public int GetNumberOfErrors()
{
2018-11-02 11:09:59 +00:00
//We will need to stop the request if trying to do this on a 1GB file
if (CanViewLogs() == false)
{
2018-11-02 11:09:59 +00:00
throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Unable to view logs, due to size"));
}
return _logViewer.GetNumberOfErrors(startDate: DateTime.Now.AddDays(-1), endDate: DateTime.Now);
}
[HttpGet]
public LogLevelCounts GetLogLevelCounts()
{
2018-11-02 11:09:59 +00:00
//We will need to stop the request if trying to do this on a 1GB file
if (CanViewLogs() == false)
{
2018-11-02 11:09:59 +00:00
throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Unable to view logs, due to size"));
}
return _logViewer.GetLogLevelCounts(startDate: DateTime.Now.AddDays(-1), endDate: DateTime.Now);
}
[HttpGet]
public IEnumerable<LogTemplate> GetMessageTemplates()
{
2018-11-02 11:09:59 +00:00
//We will need to stop the request if trying to do this on a 1GB file
if (CanViewLogs() == false)
{
2018-11-02 11:09:59 +00:00
throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Unable to view logs, due to size"));
}
return _logViewer.GetMessageTemplates(startDate: DateTime.Now.AddDays(-1), endDate: DateTime.Now);
}
[HttpGet]
public PagedResult<LogMessage> GetLogs(string orderDirection = "Descending", int pageNumber = 1, string filterExpression = null, [FromUri]string[] logLevels = null)
{
2018-11-02 11:09:59 +00:00
//We will need to stop the request if trying to do this on a 1GB file
if (CanViewLogs() == false)
{
2018-11-02 11:09:59 +00:00
throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Unable to view logs, due to size"));
}
var direction = orderDirection == "Descending" ? Direction.Descending : Direction.Ascending;
return _logViewer.GetLogs(startDate: DateTime.Now.AddDays(-1), endDate: DateTime.Now, filterExpression: filterExpression, pageNumber: pageNumber, orderDirection: direction, logLevels: logLevels);
}
[HttpGet]
public IEnumerable<SavedLogSearch> GetSavedSearches()
{
return _logViewer.GetSavedSearches();
}
[HttpPost]
public IEnumerable<SavedLogSearch> PostSavedSearch(SavedLogSearch item)
{
return _logViewer.AddSavedSearch(item.Name, item.Query);
}
[HttpPost]
public IEnumerable<SavedLogSearch> DeleteSavedSearch(SavedLogSearch item)
{
return _logViewer.DeleteSavedSearch(item.Name, item.Query);
}
}
}