2018-09-14 15:17:12 +01:00
|
|
|
|
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;
|
2018-11-02 11:09:59 +00:00
|
|
|
|
using Umbraco.Web.WebApi;
|
2018-08-27 20:05:59 +01:00
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-01 16:24:48 +00:00
|
|
|
|
private bool CanViewLogs()
|
2018-11-01 16:14:03 +00:00
|
|
|
|
{
|
2018-11-02 11:09:59 +00:00
|
|
|
|
//Can the interface deal with Large Files
|
|
|
|
|
|
if (_logViewer.CanHandleLargeLogs)
|
2018-11-01 16:24:48 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
2018-11-02 11:09:59 +00:00
|
|
|
|
//Interface CheckCanOpenLogs
|
|
|
|
|
|
return _logViewer.CheckCanOpenLogs(startDate: DateTime.Now.AddDays(-1), endDate: DateTime.Now);
|
2018-11-01 16:24:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2018-11-02 11:09:59 +00:00
|
|
|
|
public bool GetCanViewLogs()
|
2018-11-01 16:24:48 +00:00
|
|
|
|
{
|
2018-11-02 11:09:59 +00:00
|
|
|
|
return CanViewLogs();
|
2018-11-01 16:14:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-27 20:05:59 +01:00
|
|
|
|
[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-01 16:24:48 +00:00
|
|
|
|
{
|
2018-11-02 11:09:59 +00:00
|
|
|
|
throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Unable to view logs, due to size"));
|
2018-11-01 16:24:48 +00:00
|
|
|
|
}
|
2018-11-01 16:19:18 +00:00
|
|
|
|
|
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-09-14 15:17:12 +01:00
|
|
|
|
|
2018-08-27 20:05:59 +01:00
|
|
|
|
[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
|
2018-11-01 16:24:48 +00:00
|
|
|
|
if (CanViewLogs() == false)
|
|
|
|
|
|
{
|
2018-11-02 11:09:59 +00:00
|
|
|
|
throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Unable to view logs, due to size"));
|
2018-11-01 16:24:48 +00:00
|
|
|
|
}
|
2018-11-01 16:19:18 +00:00
|
|
|
|
|
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-11-02 11:09:59 +00:00
|
|
|
|
//We will need to stop the request if trying to do this on a 1GB file
|
2018-11-01 16:24:48 +00:00
|
|
|
|
if (CanViewLogs() == false)
|
|
|
|
|
|
{
|
2018-11-02 11:09:59 +00:00
|
|
|
|
throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Unable to view logs, due to size"));
|
2018-11-01 16:24:48 +00:00
|
|
|
|
}
|
2018-11-01 16:19:18 +00: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-11-02 11:09:59 +00:00
|
|
|
|
//We will need to stop the request if trying to do this on a 1GB file
|
2018-11-01 16:24:48 +00:00
|
|
|
|
if (CanViewLogs() == false)
|
|
|
|
|
|
{
|
2018-11-02 11:09:59 +00:00
|
|
|
|
throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Unable to view logs, due to size"));
|
2018-11-01 16:24:48 +00:00
|
|
|
|
}
|
2018-11-01 16:19:18 +00: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-09-12 16:47:36 +01:00
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public IEnumerable<SavedLogSearch> PostSavedSearch(SavedLogSearch item)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _logViewer.AddSavedSearch(item.Name, item.Query);
|
|
|
|
|
|
}
|
2018-09-14 15:17:12 +01:00
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public IEnumerable<SavedLogSearch> DeleteSavedSearch(SavedLogSearch item)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _logViewer.DeleteSavedSearch(item.Name, item.Query);
|
|
|
|
|
|
}
|
2018-08-27 20:05:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|