From eda6c62fccda43d7236f61b768f1ce93902b0db8 Mon Sep 17 00:00:00 2001 From: Warren Date: Tue, 31 Jul 2018 18:08:58 +0100 Subject: [PATCH] Minor change so that the text log filenames match better to old log4net style - adds in an extra . between Machine Name and the Date that gets added --- src/Umbraco.Core/Logging/Logger.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/Logging/Logger.cs b/src/Umbraco.Core/Logging/Logger.cs index dfbf65a5a1..48e448493c 100644 --- a/src/Umbraco.Core/Logging/Logger.cs +++ b/src/Umbraco.Core/Logging/Logger.cs @@ -12,18 +12,20 @@ using Serilog.Formatting.Compact; namespace Umbraco.Core.Logging { /// - /// Implements on top of log4net. + /// Implements on top of Serilog. /// public class Logger : ILogger { /// - /// Initialize a new instance of the class with a log4net configuration file. + /// Initialize a new instance of the class with a configuration file. /// - /// - public Logger(FileInfo log4NetConfigFile) + /// + public Logger(FileInfo logConfigFile) : this() { - //XmlConfigurator.Configure(log4NetConfigFile); + Log.Logger = new LoggerConfiguration() + .ReadFrom.AppSettings(filePath: AppDomain.CurrentDomain.BaseDirectory + logConfigFile) + .CreateLogger(); } // private for CreateWithDefaultConfiguration @@ -44,14 +46,16 @@ namespace Umbraco.Core.Logging .Enrich.WithProperty("AppDomainAppId", HttpRuntime.AppDomainAppId.ReplaceNonAlphanumericChars(string.Empty)) //Main .txt logfile - in similar format to older Log4Net output - .WriteTo.File($@"{AppDomain.CurrentDomain.BaseDirectory}\App_Data\Logs\UmbracoTraceLog{Environment.MachineName}.txt", + //Ends with ..txt as Date is inserted before file extension substring + .WriteTo.File($@"{AppDomain.CurrentDomain.BaseDirectory}\App_Data\Logs\UmbracoTraceLog.{Environment.MachineName}..txt", 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}") //.clef format (Compact log event format, that can be imported into local SEQ & will make searching/filtering logs easier) - .WriteTo.File(new CompactJsonFormatter(), $@"{AppDomain.CurrentDomain.BaseDirectory}\App_Data\Logs\UmbracoTraceLog{Environment.MachineName}.json", + //Ends with ..txt as Date is inserted before file extension substring + .WriteTo.File(new CompactJsonFormatter(), $@"{AppDomain.CurrentDomain.BaseDirectory}\App_Data\Logs\UmbracoTraceLog.{Environment.MachineName}..json", rollingInterval: RollingInterval.Day, //Create a new JSON file every day retainedFileCountLimit: null, //Setting to null means we keep all files - default is 31 days restrictedToMinimumLevel: LogEventLevel.Debug)