Add LogLevel Blacklist
This commit is contained in:
parent
f0e3ccc41b
commit
24dc68b308
2 changed files with 20 additions and 6 deletions
14
Logger.cs
14
Logger.cs
|
|
@ -133,6 +133,8 @@ public class Logger : ILogger
|
||||||
});
|
});
|
||||||
|
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
if (!_loggerObjects.FileBlackList.Contains(currentLog.LogLevel))
|
||||||
{
|
{
|
||||||
Byte[] FileWrite = Encoding.UTF8.GetBytes($"[{currentLog.TimeOfEvent:dd.MM.yyyy HH:mm:ss}] [{LogLevelText}] {LogMessage}\n{(currentLog.Exception is not null ? $"{currentLog.Exception}\n" : "")}");
|
Byte[] FileWrite = Encoding.UTF8.GetBytes($"[{currentLog.TimeOfEvent:dd.MM.yyyy HH:mm:ss}] [{LogLevelText}] {LogMessage}\n{(currentLog.Exception is not null ? $"{currentLog.Exception}\n" : "")}");
|
||||||
if (OpenedFile != null)
|
if (OpenedFile != null)
|
||||||
|
|
@ -141,6 +143,7 @@ public class Logger : ILogger
|
||||||
OpenedFile.Flush();
|
OpenedFile.Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogFatal($"Couldn't write log to file: {ex}");
|
LogFatal($"Couldn't write log to file: {ex}");
|
||||||
|
|
@ -192,6 +195,15 @@ public class Logger : ILogger
|
||||||
_loggerObjects.Blacklist.Add(blacklist);
|
_loggerObjects.Blacklist.Add(blacklist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add blacklisted log level to not save
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="blacklist"></param>
|
||||||
|
public static void AddLogLevelBlacklist(LoggerObjects.LogLevel level)
|
||||||
|
{
|
||||||
|
_loggerObjects.FileBlackList.Add(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -365,7 +377,7 @@ public class Logger : ILogger
|
||||||
LogLevel = logLevel switch
|
LogLevel = logLevel switch
|
||||||
{
|
{
|
||||||
Microsoft.Extensions.Logging.LogLevel.Debug => LoggerObjects.LogLevel.DEBUG2,
|
Microsoft.Extensions.Logging.LogLevel.Debug => LoggerObjects.LogLevel.DEBUG2,
|
||||||
Microsoft.Extensions.Logging.LogLevel.Trace => LoggerObjects.LogLevel.TRACE,
|
Microsoft.Extensions.Logging.LogLevel.Trace => LoggerObjects.LogLevel.TRACE2,
|
||||||
Microsoft.Extensions.Logging.LogLevel.Information => LoggerObjects.LogLevel.INFO,
|
Microsoft.Extensions.Logging.LogLevel.Information => LoggerObjects.LogLevel.INFO,
|
||||||
Microsoft.Extensions.Logging.LogLevel.Warning => LoggerObjects.LogLevel.WARN,
|
Microsoft.Extensions.Logging.LogLevel.Warning => LoggerObjects.LogLevel.WARN,
|
||||||
Microsoft.Extensions.Logging.LogLevel.Error => LoggerObjects.LogLevel.ERROR,
|
Microsoft.Extensions.Logging.LogLevel.Error => LoggerObjects.LogLevel.ERROR,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ public class LoggerObjects
|
||||||
{
|
{
|
||||||
internal List<LogEntry> LogsToPost = new();
|
internal List<LogEntry> LogsToPost = new();
|
||||||
internal List<string> Blacklist = new();
|
internal List<string> Blacklist = new();
|
||||||
|
internal List<LogLevel> FileBlackList = new();
|
||||||
|
|
||||||
public class LogEntry
|
public class LogEntry
|
||||||
{
|
{
|
||||||
|
|
@ -22,6 +23,7 @@ public class LoggerObjects
|
||||||
INFO,
|
INFO,
|
||||||
DEBUG,
|
DEBUG,
|
||||||
DEBUG2,
|
DEBUG2,
|
||||||
TRACE
|
TRACE,
|
||||||
|
TRACE2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue