Remove build files
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Logger;
|
||||
|
||||
/// <summary>
|
||||
@@ -18,6 +20,41 @@ public static class LoggerFactory
|
||||
return new CompositeLogger(consoleLogger, fileLogger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a logger from configuration section
|
||||
/// </summary>
|
||||
public static ILogger CreateFromConfiguration(IConfiguration configuration)
|
||||
{
|
||||
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
|
||||
|
||||
var section = configuration.GetSection("Logger");
|
||||
var consoleLevelString = section.GetValue("ConsoleMinimumLevel", "Trace");
|
||||
var consoleLevel = ParseLogLevel(consoleLevelString);
|
||||
|
||||
var fileOptions = section.GetSection("File").Get<FileLoggerOptions>() ?? new FileLoggerOptions();
|
||||
|
||||
return CreateCompositeLogger(consoleLevel, fileOptions);
|
||||
}
|
||||
|
||||
private static LogLevel ParseLogLevel(string? level)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(level))
|
||||
return LogLevel.Trace;
|
||||
|
||||
return level.Trim().ToLowerInvariant() switch
|
||||
{
|
||||
"trace" => LogLevel.Trace,
|
||||
"debug" => LogLevel.Debug,
|
||||
"info" => LogLevel.Info,
|
||||
"information" => LogLevel.Info,
|
||||
"warn" => LogLevel.Warning,
|
||||
"warning" => LogLevel.Warning,
|
||||
"error" => LogLevel.Error,
|
||||
"fatal" => LogLevel.Fatal,
|
||||
_ => LogLevel.Trace
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a console-only logger
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user