Adds our Serilog Enricher so that we can map Serilog log levels to Log4Net levels and use it the text log file so that the logfiles still look the same as previously
This commit is contained in:
@@ -8,6 +8,7 @@ using Umbraco.Core.Diagnostics;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using Serilog.Formatting.Compact;
|
||||
using Umbraco.Core.Logging.SerilogExtensions;
|
||||
|
||||
namespace Umbraco.Core.Logging
|
||||
{
|
||||
@@ -43,6 +44,7 @@ namespace Umbraco.Core.Logging
|
||||
.Enrich.WithThreadId()
|
||||
.Enrich.WithProperty("AppDomainId", AppDomain.CurrentDomain.Id)
|
||||
.Enrich.WithProperty("AppDomainAppId", HttpRuntime.AppDomainAppId.ReplaceNonAlphanumericChars(string.Empty))
|
||||
.Enrich.With<Log4NetLevelMapperEnricher>()
|
||||
|
||||
//Main .txt logfile - in similar format to older Log4Net output
|
||||
//Ends with ..txt as Date is inserted before file extension substring
|
||||
@@ -50,7 +52,7 @@ namespace Umbraco.Core.Logging
|
||||
rollingInterval: RollingInterval.Day,
|
||||
restrictedToMinimumLevel: LogEventLevel.Debug,
|
||||
retainedFileCountLimit: null, //Setting to null means we keep all files - default is 31 days
|
||||
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss,fff} [P{ProcessId}/D{AppDomainId}/T{ThreadId}] {Level:u4} {Message:lj}{NewLine}{Exception}")
|
||||
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss,fff} [P{ProcessId}/D{AppDomainId}/T{ThreadId}] {Log4NetLevel} {Message:lj}{NewLine}{Exception}")
|
||||
|
||||
//.clef format (Compact log event format, that can be imported into local SEQ & will make searching/filtering logs easier)
|
||||
//Ends with ..txt as Date is inserted before file extension substring
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Umbraco.Core.Logging.SerilogExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// This is used to create a new property in Logs called 'Log4NetLevel'
|
||||
/// So that we can map Serilog levels to Log4Net levels - so log files stay consistent
|
||||
/// </summary>
|
||||
public class Log4NetLevelMapperEnricher : ILogEventEnricher
|
||||
{
|
||||
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
|
||||
{
|
||||
var log4NetLevel = string.Empty;
|
||||
|
||||
switch (logEvent.Level)
|
||||
{
|
||||
case LogEventLevel.Debug:
|
||||
log4NetLevel = "DEBUG";
|
||||
break;
|
||||
|
||||
case LogEventLevel.Error:
|
||||
log4NetLevel = "ERROR";
|
||||
break;
|
||||
|
||||
case LogEventLevel.Fatal:
|
||||
log4NetLevel = "FATAL";
|
||||
break;
|
||||
|
||||
case LogEventLevel.Information:
|
||||
log4NetLevel = "INFO";
|
||||
break;
|
||||
|
||||
case LogEventLevel.Verbose:
|
||||
log4NetLevel = "ALL";
|
||||
break;
|
||||
|
||||
case LogEventLevel.Warning:
|
||||
log4NetLevel = "WARN";
|
||||
break;
|
||||
}
|
||||
|
||||
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Log4NetLevel", log4NetLevel));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -326,6 +326,7 @@
|
||||
<Compile Include="IO\MediaPathSchemes\OriginalMediaPathScheme.cs" />
|
||||
<Compile Include="IO\MediaPathSchemes\TwoGuidsMediaPathScheme.cs" />
|
||||
<Compile Include="KeyValuePairExtensions.cs" />
|
||||
<Compile Include="Logging\SerilogExtensions\Log4NetLevelMapperEnricher.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" />
|
||||
|
||||
Reference in New Issue
Block a user