From 021e9d1b65fa39a461a50548fa8aad7617f69ba6 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Tue, 21 Feb 2023 21:45:02 +0600 Subject: [PATCH] breaking change in ContextLogger constructor --- DTLib.Logging/DTLibInternalLogging.cs | 2 +- DTLib.Logging/Loggers/ContextLogger.cs | 19 ++++++++----------- DTLib.Tests/Program.cs | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/DTLib.Logging/DTLibInternalLogging.cs b/DTLib.Logging/DTLibInternalLogging.cs index f16bd3a..ca38f5d 100644 --- a/DTLib.Logging/DTLibInternalLogging.cs +++ b/DTLib.Logging/DTLibInternalLogging.cs @@ -17,7 +17,7 @@ public static class DTLibInternalLogging public static void SetLogger(ILogger logger) { - _loggerContext = new ContextLogger(logger, "DTLib"); + _loggerContext = new ContextLogger("DTLib",logger); PublicLog.LogEvent+=LogHandler; } diff --git a/DTLib.Logging/Loggers/ContextLogger.cs b/DTLib.Logging/Loggers/ContextLogger.cs index 36553ec..e9f7bcf 100644 --- a/DTLib.Logging/Loggers/ContextLogger.cs +++ b/DTLib.Logging/Loggers/ContextLogger.cs @@ -6,11 +6,17 @@ public class ContextLogger : ILogger public ILogger ParentLogger; public readonly string Context; - public ContextLogger(ILogger parentLogger, string context) + public ContextLogger(string context,ILogger parentLogger) { ParentLogger = parentLogger; Context = context; } + + /// Appends subContext to Context + public void Log(string subContext, LogSeverity severity, object message, ILogFormat format) + { + ParentLogger.Log($"{Context}/{subContext}", severity, message, format); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Log(LogSeverity severity, object message) @@ -42,10 +48,7 @@ public class ContextLogger : ILogger public void LogError(Exception ex) => ParentLogger.LogError(Context, ex); - public void Dispose() - { - ParentLogger.Dispose(); - } + public void Dispose() => ParentLogger.Dispose(); public ILogFormat Format => ParentLogger.Format; @@ -72,10 +75,4 @@ public class ContextLogger : ILogger get => ParentLogger.ErrorLogEnabled; set => ParentLogger.ErrorLogEnabled = value; } - - /// Appends subContext to Context - public void Log(string subContext, LogSeverity severity, object message, ILogFormat format) - { - ParentLogger.Log($"{Context}/{subContext}", severity, message, format); - } } \ No newline at end of file diff --git a/DTLib.Tests/Program.cs b/DTLib.Tests/Program.cs index db546e5..32dfd7d 100644 --- a/DTLib.Tests/Program.cs +++ b/DTLib.Tests/Program.cs @@ -25,7 +25,7 @@ public static class Program System.Console.InputEncoding = Encoding.UTF8; Logger=new CompositeLogger(new ConsoleLogger(), new FileLogger("logs", "DTLib.Tests")); - var mainContext = new ContextLogger(Logger, "Main"); + var mainContext = new ContextLogger("Main", Logger); DTLibInternalLogging.SetLogger(Logger); try