Adds LogViewerComponent & registers singleton in DI (3rd party devs will have to disable this component & register their own implementation)
Get some more of the basic WebAPI stubs fleshed out to get some data to start using in the UI layer
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Umbraco.Core.Logging.Viewer
|
||||
{
|
||||
@@ -17,14 +16,14 @@ namespace Umbraco.Core.Logging.Viewer
|
||||
LogLevelCounts GetLogLevelCounts();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the top 5 common log message templates and their counts
|
||||
/// Returns the top common log message templates and their counts
|
||||
/// </summary>
|
||||
IEnumerable<CommonLogMessage> GetCommonLogMessages();
|
||||
IEnumerable<CommonLogMessage> GetCommonLogMessages(int numberOfResults = 10);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the collection of logs
|
||||
/// </summary>
|
||||
IEnumerable<LogEvent> GetLogs();
|
||||
IEnumerable<LogMessage> GetLogs();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ using Serilog.Formatting.Compact.Reader;
|
||||
|
||||
namespace Umbraco.Core.Logging.Viewer
|
||||
{
|
||||
public class LogViewer : ILogViewer
|
||||
public class JsonLogViewer : ILogViewer
|
||||
{
|
||||
private List<LogEvent> _logs;
|
||||
private List<LogEvent> _logs = new List<LogEvent>();
|
||||
|
||||
public LogViewer()
|
||||
public JsonLogViewer()
|
||||
{
|
||||
var filePath = $@"{AppDomain.CurrentDomain.BaseDirectory}\App_Data\Logs\UmbracoTraceLog.DELLBOOK.20180824.json";
|
||||
var filePath = $@"{AppDomain.CurrentDomain.BaseDirectory}\App_Data\Logs\UmbracoTraceLog.DELLBOOK.20180828.json";
|
||||
|
||||
//Open log file
|
||||
using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
@@ -48,16 +48,37 @@ namespace Umbraco.Core.Logging.Viewer
|
||||
};
|
||||
}
|
||||
|
||||
public IEnumerable<CommonLogMessage> GetCommonLogMessages()
|
||||
public IEnumerable<CommonLogMessage> GetCommonLogMessages(int numberOfResults)
|
||||
{
|
||||
var messages = new List<CommonLogMessage>();
|
||||
return messages;
|
||||
var templates = _logs.GroupBy(x => x.MessageTemplate.Text)
|
||||
.Select(g => new CommonLogMessage { MessageTemplate = g.Key, Count = g.Count() })
|
||||
.OrderByDescending(x => x.Count)
|
||||
.Take(numberOfResults);
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
public IEnumerable<LogEvent> GetLogs()
|
||||
public IEnumerable<LogMessage> GetLogs()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var messages = new List<LogMessage>();
|
||||
var logs = _logs.Take(20);
|
||||
|
||||
foreach(var log in logs)
|
||||
{
|
||||
var logItem = new LogMessage
|
||||
{
|
||||
Level = log.Level,
|
||||
Properties = log.Properties,
|
||||
Timestamp = log.Timestamp,
|
||||
MessageTemplateText = log.MessageTemplate.Text, //Not necesarily worried about token position just the message text itself
|
||||
RenderedMessage = log.RenderMessage(), //Not returning LogEvent itself from Serilog (as we don't get the rendered txt log back)
|
||||
Exception = log.Exception
|
||||
};
|
||||
|
||||
messages.Add(logItem);
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
src/Umbraco.Core/Logging/Viewer/LogMessage.cs
Normal file
42
src/Umbraco.Core/Logging/Viewer/LogMessage.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Serilog.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Umbraco.Core.Logging.Viewer
|
||||
{
|
||||
public class LogMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// The time at which the logevent occurred.
|
||||
/// </summary>
|
||||
public DateTimeOffset Timestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The level of the event.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public LogEventLevel Level { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The message template describing the logevent.
|
||||
/// </summary>
|
||||
public string MessageTemplateText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The message template filled with the logevent properties.
|
||||
/// </summary>
|
||||
public string RenderedMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Properties associated with the logevent, including those presented in Serilog.Events.LogEvent.MessageTemplate.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, LogEventPropertyValue> Properties { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An exception associated with the logevent, or null.
|
||||
/// </summary>
|
||||
public Exception Exception { get; set; }
|
||||
}
|
||||
}
|
||||
14
src/Umbraco.Core/Logging/Viewer/LogViewerComponent.cs
Normal file
14
src/Umbraco.Core/Logging/Viewer/LogViewerComponent.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Umbraco.Core.Components;
|
||||
using Umbraco.Core.Composing;
|
||||
|
||||
namespace Umbraco.Core.Logging.Viewer
|
||||
{
|
||||
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
|
||||
public class LogViewerComponent : UmbracoComponentBase, IUmbracoCoreComponent
|
||||
{
|
||||
public override void Compose(Composition composition)
|
||||
{
|
||||
composition.Container.RegisterSingleton<ILogViewer, JsonLogViewer>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -337,7 +337,9 @@
|
||||
<Compile Include="Logging\Viewer\CommonLogMessage.cs" />
|
||||
<Compile Include="Logging\Viewer\ILogViewer.cs" />
|
||||
<Compile Include="Logging\Viewer\LogLevelCounts.cs" />
|
||||
<Compile Include="Logging\Viewer\LogViewer.cs" />
|
||||
<Compile Include="Logging\Viewer\JsonLogViewer.cs" />
|
||||
<Compile Include="Logging\Viewer\LogMessage.cs" />
|
||||
<Compile Include="Logging\Viewer\LogViewerComponent.cs" />
|
||||
<Compile Include="Migrations\MigrationBase_Extra.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_7_10_0\RenamePreviewFolder.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_7_12_0\AddRelationTypeForMediaFolderOnDelete.cs" />
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
using System.Web.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core.Logging.Viewer;
|
||||
using Umbraco.Web.Mvc;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
/// <summary>
|
||||
/// Backoffice controller supporting the dashboard for language administration.
|
||||
/// Backoffice controller supporting the dashboard for viewing logs with some simple graphs & filtering
|
||||
/// </summary>
|
||||
[PluginController("UmbracoApi")]
|
||||
public class LogsController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
private LogViewer _logViewer;
|
||||
private ILogViewer _logViewer;
|
||||
|
||||
public LogsController()
|
||||
public LogsController(ILogViewer logViewer)
|
||||
{
|
||||
_logViewer = new LogViewer();
|
||||
_logViewer = logViewer;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -22,11 +23,24 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
return _logViewer.GetNumberOfErrors();
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public LogLevelCounts GetLogLevelCounts()
|
||||
{
|
||||
return _logViewer.GetLogLevelCounts();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IEnumerable<CommonLogMessage> GetCommonLogMessages()
|
||||
{
|
||||
return _logViewer.GetCommonLogMessages();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IEnumerable<LogMessage> GetLogs()
|
||||
{
|
||||
return _logViewer.GetLogs();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user