From 775b8e3a6ac1b42f821aeaa994636319bbd7482a Mon Sep 17 00:00:00 2001 From: glax Date: Fri, 2 Feb 2024 19:43:26 +0100 Subject: [PATCH] Make filterLevel changeable at runtime --- GlaxLogger/GlaxLogger.csproj | 2 +- GlaxLogger/Logger.cs | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/GlaxLogger/GlaxLogger.csproj b/GlaxLogger/GlaxLogger.csproj index 12509a3..1d43d68 100644 --- a/GlaxLogger/GlaxLogger.csproj +++ b/GlaxLogger/GlaxLogger.csproj @@ -7,7 +7,7 @@ Glax https://git.bernloehr.eu/glax/GlaxLogger git - 1.0.3 + 1.0.4 diff --git a/GlaxLogger/Logger.cs b/GlaxLogger/Logger.cs index f879ca4..8c6826f 100644 --- a/GlaxLogger/Logger.cs +++ b/GlaxLogger/Logger.cs @@ -5,13 +5,12 @@ namespace GlaxLogger; public class Logger : ILogger, IDisposable, IAsyncDisposable { - private readonly LogLevel _filterLevel; + private LogLevel _filterLevel; private readonly FileStream _allMessageLogfile, _filteredLogfile; private readonly ConsoleColor _defaultForegroundColor = Console.ForegroundColor; private readonly ConsoleColor _defaultBackgroundColor = Console.BackgroundColor; private readonly TextWriter _consoleOut; - public Logger(LogLevel filteredLevel = LogLevel.Warning, string? outputFolderPath = null, TextWriter? consoleOut = null) { this._filterLevel = filteredLevel; @@ -46,6 +45,12 @@ public class Logger : ILogger, IDisposable, IAsyncDisposable return logLevel >= _filterLevel; } + public void UpdateLogLevel(LogLevel filterLevel) + { + this._filterLevel = filterLevel; + Log(LogLevel.None, new EventId(), $"Change LogLevel to {filterLevel}", null, (s, exception) => s); + } + public IDisposable? BeginScope(TState state) where TState : notnull { return null;