From cd2a70a5207780997d765575b1bbb17989463222 Mon Sep 17 00:00:00 2001 From: Warren Date: Mon, 30 Jul 2018 16:36:38 +0100 Subject: [PATCH] Get logger to output as same file as old Log4Net and in same format (only diff currently is the log level type in the log file) Ensures we use the calling type in the Umbraco ILogger and passes it onto Serilog --- src/Umbraco.Core/Logging/Logger.cs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Core/Logging/Logger.cs b/src/Umbraco.Core/Logging/Logger.cs index ac0cd091da..b72f86e7aa 100644 --- a/src/Umbraco.Core/Logging/Logger.cs +++ b/src/Umbraco.Core/Logging/Logger.cs @@ -1,14 +1,12 @@ using System; -using System.Diagnostics; -using System.Globalization; using System.IO; -using System.Linq; using System.Reflection; using System.Threading; using System.Web; using Umbraco.Core.Configuration; using Umbraco.Core.Diagnostics; using Serilog; +using Serilog.Events; namespace Umbraco.Core.Logging { @@ -37,7 +35,11 @@ namespace Umbraco.Core.Logging .Enrich.WithThreadId() .Enrich.WithProperty("AppDomainId", AppDomain.CurrentDomain.Id) .Enrich.WithProperty("AppDomainAppId", HttpRuntime.AppDomainAppId.ReplaceNonAlphanumericChars(string.Empty)) - .WriteTo.File(AppDomain.CurrentDomain.BaseDirectory + "\\logs\\warren.txt", rollingInterval: RollingInterval.Day) + .WriteTo.File(AppDomain.CurrentDomain.BaseDirectory + @"\App_Data\Logs\UmbracoTraceLog.txt", //Our main app Logfile + 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}") .CreateLogger(); } @@ -146,14 +148,14 @@ namespace Umbraco.Core.Logging public void Warn(Type reporting, Exception exception, string message) { var logger = Log.Logger; - logger?.Warning(message, exception); + logger?.ForContext(reporting).Warning(message, exception); } /// public void Warn(Type reporting, Exception exception, Func messageBuilder) { var logger = Log.Logger; - logger?.Warning(messageBuilder(), exception); + logger?.ForContext(reporting).Warning(messageBuilder(), exception); } ///// @@ -182,14 +184,14 @@ namespace Umbraco.Core.Logging public void Info(Type reporting, string message) { var logger = Log.Logger; - logger?.Information(message); + logger?.ForContext(reporting).Information(message); } /// public void Info(Type reporting, Func generateMessage) { var logger = Log.Logger; - logger?.Information(generateMessage()); + logger?.ForContext(reporting).Information(generateMessage()); } ///// @@ -212,14 +214,14 @@ namespace Umbraco.Core.Logging public void Debug(Type reporting, string message) { var logger = Log.Logger; - logger?.Debug(message); + logger?.ForContext(reporting).Debug(message); } /// public void Debug(Type reporting, Func messageBuilder) { var logger = Log.Logger; - logger?.Debug(messageBuilder()); + logger?.ForContext(reporting).Debug(messageBuilder()); } /////