From 0dd9431c28e508bada8fea94cbdd76114e6a83df Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Wed, 4 Jan 2023 05:25:24 +0600 Subject: [PATCH] ContextLogger --- DTLib.Logging/DTLib.Logging.csproj | 4 +- .../ContextLogger.cs} | 41 ++++++++++++++++++- 2 files changed, 41 insertions(+), 4 deletions(-) rename DTLib.Logging/{LoggerContext.cs => Loggers/ContextLogger.cs} (57%) diff --git a/DTLib.Logging/DTLib.Logging.csproj b/DTLib.Logging/DTLib.Logging.csproj index 9750366..7768884 100644 --- a/DTLib.Logging/DTLib.Logging.csproj +++ b/DTLib.Logging/DTLib.Logging.csproj @@ -2,7 +2,7 @@ DTLib.Logging - 1.0.3 + 1.0.4 Timerix Loggers with dependency injection GIT @@ -30,6 +30,6 @@ - + diff --git a/DTLib.Logging/LoggerContext.cs b/DTLib.Logging/Loggers/ContextLogger.cs similarity index 57% rename from DTLib.Logging/LoggerContext.cs rename to DTLib.Logging/Loggers/ContextLogger.cs index 6d8c59d..5b2e3ae 100644 --- a/DTLib.Logging/LoggerContext.cs +++ b/DTLib.Logging/Loggers/ContextLogger.cs @@ -1,12 +1,12 @@ namespace DTLib.Logging.New; /// wrapper around ILogger and LoggerExtensions that stores context -public class LoggerContext +public class ContextLogger : ILogger { public ILogger Logger; public readonly string Context; - public LoggerContext(ILogger logger, string context) + public ContextLogger(ILogger logger, string context) { Logger = logger; Context = context; @@ -41,4 +41,41 @@ public class LoggerContext [MethodImpl(MethodImplOptions.AggressiveInlining)] public void LogError(Exception ex) => Logger.LogError(Context, ex); + + public void Dispose() + { + Logger.Dispose(); + } + + public ILogFormat Format => Logger.Format; + + public bool DebugLogEnabled + { + get => Logger.DebugLogEnabled; + set => Logger.DebugLogEnabled = value; + } + + public bool InfoLogEnabled + { + get => Logger.InfoLogEnabled; + set => Logger.InfoLogEnabled = value; + } + + public bool WarnLogEnabled + { + get => Logger.WarnLogEnabled; + set => Logger.WarnLogEnabled = value; + } + + public bool ErrorLogenabled + { + get => Logger.ErrorLogenabled; + set => Logger.ErrorLogenabled = value; + } + + /// Appends subContext to Context + public void Log(string subContext, LogSeverity severity, object message, ILogFormat format) + { + Logger.Log($"{Context}/{subContext}", severity, message, format); + } } \ No newline at end of file