Make filterLevel changeable at runtime

This commit is contained in:
glax 2024-02-02 19:43:26 +01:00
parent 13ba0fedea
commit 775b8e3a6a
2 changed files with 8 additions and 3 deletions

View File

@ -7,7 +7,7 @@
<Authors>Glax</Authors>
<RepositoryUrl>https://git.bernloehr.eu/glax/GlaxLogger</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>1.0.3</Version>
<Version>1.0.4</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -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>(TState state) where TState : notnull
{
return null;