Files
Umbraco-CMS/src/Umbraco.Web.BackOffice/Controllers/LogViewerController.cs

146 lines
5.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
Merge remote-tracking branch 'origin/netcore/dev' into netcore/netcore # Conflicts: # src/Umbraco.Configuration/Legacy/GlobalSettings.cs # src/Umbraco.Core/Configuration/IGlobalSettings.cs # src/Umbraco.Core/Models/ContentBaseExtensions.cs # src/Umbraco.Core/Routing/ContentFinderByRedirectUrl.cs # src/Umbraco.Core/Routing/DefaultUrlProvider.cs # src/Umbraco.Core/Runtime/MainDom.cs # src/Umbraco.Core/Services/IRuntimeState.cs # src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs # src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs # src/Umbraco.Infrastructure/RuntimeState.cs # src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs # src/Umbraco.Tests/Runtimes/StandaloneTests.cs # src/Umbraco.Tests/TestHelpers/TestObjects.cs # src/Umbraco.Web.BackOffice/Controllers/LogViewerController.cs # src/Umbraco.Web.BackOffice/Controllers/UsersController.cs # src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs # src/Umbraco.Web.BackOffice/PropertyEditors/RteEmbedController.cs # src/Umbraco.Web.BackOffice/Trees/DictionaryTreeController.cs # src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Default.cshtml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/da.xml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en.xml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en_us.xml # src/Umbraco.Web.UI/Umbraco/config/lang/cs.xml # src/Umbraco.Web.UI/Views/Partials/Grid/Editors/Rte.cshtml # src/Umbraco.Web/Controllers/UmbLoginController.cs # src/Umbraco.Web/Install/Controllers/InstallController.cs # src/Umbraco.Web/PublishedElementExtensions.cs # src/Umbraco.Web/Runtime/WebInitialComposer.cs # src/Umbraco.Web/UmbracoHelper.cs # src/Umbraco.Web/UmbracoInjectedModule.cs # src/Umbraco.Web/UrlHelperExtensions.cs # src/Umbraco.Web/UrlHelperRenderExtensions.cs # src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs
2020-12-01 11:34:13 +01:00
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Core.Logging.Viewer;
using Umbraco.Web.Common.ActionsResults;
using Umbraco.Web.Common.Attributes;
Merge remote-tracking branch 'origin/netcore/dev' into netcore/netcore # Conflicts: # src/Umbraco.Configuration/Legacy/GlobalSettings.cs # src/Umbraco.Core/Configuration/IGlobalSettings.cs # src/Umbraco.Core/Models/ContentBaseExtensions.cs # src/Umbraco.Core/Routing/ContentFinderByRedirectUrl.cs # src/Umbraco.Core/Routing/DefaultUrlProvider.cs # src/Umbraco.Core/Runtime/MainDom.cs # src/Umbraco.Core/Services/IRuntimeState.cs # src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs # src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs # src/Umbraco.Infrastructure/RuntimeState.cs # src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs # src/Umbraco.Tests/Runtimes/StandaloneTests.cs # src/Umbraco.Tests/TestHelpers/TestObjects.cs # src/Umbraco.Web.BackOffice/Controllers/LogViewerController.cs # src/Umbraco.Web.BackOffice/Controllers/UsersController.cs # src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs # src/Umbraco.Web.BackOffice/PropertyEditors/RteEmbedController.cs # src/Umbraco.Web.BackOffice/Trees/DictionaryTreeController.cs # src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Default.cshtml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/da.xml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en.xml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en_us.xml # src/Umbraco.Web.UI/Umbraco/config/lang/cs.xml # src/Umbraco.Web.UI/Views/Partials/Grid/Editors/Rte.cshtml # src/Umbraco.Web/Controllers/UmbLoginController.cs # src/Umbraco.Web/Install/Controllers/InstallController.cs # src/Umbraco.Web/PublishedElementExtensions.cs # src/Umbraco.Web/Runtime/WebInitialComposer.cs # src/Umbraco.Web/UmbracoHelper.cs # src/Umbraco.Web/UmbracoInjectedModule.cs # src/Umbraco.Web/UrlHelperExtensions.cs # src/Umbraco.Web/UrlHelperRenderExtensions.cs # src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs
2020-12-01 11:34:13 +01:00
using Umbraco.Web.Common.Authorization;
using Constants = Umbraco.Cms.Core.Constants;
namespace Umbraco.Cms.Web.BackOffice.Controllers
{
/// <summary>
/// Backoffice controller supporting the dashboard for viewing logs with some simple graphs & filtering
/// </summary>
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
Merge remote-tracking branch 'origin/netcore/dev' into netcore/netcore # Conflicts: # src/Umbraco.Configuration/Legacy/GlobalSettings.cs # src/Umbraco.Core/Configuration/IGlobalSettings.cs # src/Umbraco.Core/Models/ContentBaseExtensions.cs # src/Umbraco.Core/Routing/ContentFinderByRedirectUrl.cs # src/Umbraco.Core/Routing/DefaultUrlProvider.cs # src/Umbraco.Core/Runtime/MainDom.cs # src/Umbraco.Core/Services/IRuntimeState.cs # src/Umbraco.Infrastructure/Compose/NotificationsComponent.cs # src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs # src/Umbraco.Infrastructure/RuntimeState.cs # src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs # src/Umbraco.Tests/Runtimes/StandaloneTests.cs # src/Umbraco.Tests/TestHelpers/TestObjects.cs # src/Umbraco.Web.BackOffice/Controllers/LogViewerController.cs # src/Umbraco.Web.BackOffice/Controllers/UsersController.cs # src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs # src/Umbraco.Web.BackOffice/PropertyEditors/RteEmbedController.cs # src/Umbraco.Web.BackOffice/Trees/DictionaryTreeController.cs # src/Umbraco.Web.UI.NetCore/umbraco/UmbracoBackOffice/Default.cshtml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/da.xml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en.xml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en_us.xml # src/Umbraco.Web.UI/Umbraco/config/lang/cs.xml # src/Umbraco.Web.UI/Views/Partials/Grid/Editors/Rte.cshtml # src/Umbraco.Web/Controllers/UmbLoginController.cs # src/Umbraco.Web/Install/Controllers/InstallController.cs # src/Umbraco.Web/PublishedElementExtensions.cs # src/Umbraco.Web/Runtime/WebInitialComposer.cs # src/Umbraco.Web/UmbracoHelper.cs # src/Umbraco.Web/UmbracoInjectedModule.cs # src/Umbraco.Web/UrlHelperExtensions.cs # src/Umbraco.Web/UrlHelperRenderExtensions.cs # src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs
2020-12-01 11:34:13 +01:00
[Authorize(Policy = AuthorizationPolicies.SectionAccessSettings)]
public class LogViewerController : UmbracoAuthorizedJsonController
{
private readonly ILogViewer _logViewer;
public LogViewerController(ILogViewer logViewer)
{
_logViewer = logViewer ?? throw new ArgumentNullException(nameof(logViewer));
}
private bool CanViewLogs(LogTimePeriod logTimePeriod)
{
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(logTimePeriod);
}
[HttpGet]
public bool GetCanViewLogs([FromQuery] DateTime? startDate = null,[FromQuery] DateTime? endDate = null)
{
var logTimePeriod = GetTimePeriod(startDate, endDate);
return CanViewLogs(logTimePeriod);
}
[HttpGet]
public ActionResult<int> GetNumberOfErrors([FromQuery] DateTime? startDate = null,[FromQuery] DateTime? endDate = null)
{
var logTimePeriod = GetTimePeriod(startDate, endDate);
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(logTimePeriod) == false)
{
return ValidationErrorResult.CreateNotificationValidationErrorResult("Unable to view logs, due to size");
}
return _logViewer.GetNumberOfErrors(logTimePeriod);
}
[HttpGet]
public ActionResult<LogLevelCounts> GetLogLevelCounts([FromQuery] DateTime? startDate = null,[FromQuery] DateTime? endDate = null)
{
var logTimePeriod = GetTimePeriod(startDate, endDate);
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(logTimePeriod) == false)
{
return ValidationErrorResult.CreateNotificationValidationErrorResult("Unable to view logs, due to size");
}
return _logViewer.GetLogLevelCounts(logTimePeriod);
}
[HttpGet]
public ActionResult<IEnumerable<LogTemplate>> GetMessageTemplates([FromQuery] DateTime? startDate = null,[FromQuery] DateTime? endDate = null)
{
var logTimePeriod = GetTimePeriod(startDate, endDate);
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(logTimePeriod) == false)
{
return ValidationErrorResult.CreateNotificationValidationErrorResult("Unable to view logs, due to size");
}
return new ActionResult<IEnumerable<LogTemplate>>(_logViewer.GetMessageTemplates(logTimePeriod));
}
[HttpGet]
public ActionResult<PagedResult<LogMessage>> GetLogs(string orderDirection = "Descending", int pageNumber = 1, string filterExpression = null, [FromQuery(Name = "logLevels[]")]string[] logLevels = null, [FromQuery]DateTime? startDate = null, [FromQuery]DateTime? endDate = null)
{
var logTimePeriod = GetTimePeriod(startDate, endDate);
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(logTimePeriod) == false)
{
return ValidationErrorResult.CreateNotificationValidationErrorResult("Unable to view logs, due to size");
}
var direction = orderDirection == "Descending" ? Direction.Descending : Direction.Ascending;
return _logViewer.GetLogs(logTimePeriod, filterExpression: filterExpression, pageNumber: pageNumber, orderDirection: direction, logLevels: logLevels);
}
private static LogTimePeriod GetTimePeriod(DateTime? startDate, DateTime? endDate)
{
if (startDate == null || endDate == null)
{
var now = DateTime.Now;
if (startDate == null)
{
startDate = now.AddDays(-1);
}
if (endDate == null)
{
endDate = now;
}
}
return new LogTimePeriod(startDate.Value, endDate.Value);
}
[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);
}
[HttpGet]
public string GetLogLevel()
{
return _logViewer.GetLogLevel();
}
}
}