Skip to content

Commit

Permalink
Fixed an issue with Serilog not respecting the default log level.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew McLachlan committed Jan 30, 2024
1 parent 0644da7 commit 54cdfa8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Asm.Serilog/LoggingConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@ public static LoggerConfiguration ConfigureLogging(LoggerConfiguration configura

public static LoggerConfiguration ConfigureLogging(LoggerConfiguration loggerConfiguration, IConfiguration configuration, IHostEnvironment hostEnvironment)
{
if (loggerConfiguration == null) throw new ArgumentNullException(nameof(loggerConfiguration));
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
if (hostEnvironment == null) throw new ArgumentNullException(nameof(hostEnvironment));
ArgumentNullException.ThrowIfNull(loggerConfiguration);
ArgumentNullException.ThrowIfNull(configuration);
ArgumentNullException.ThrowIfNull(hostEnvironment);

loggerConfiguration
.Enrich.FromLogContext()
.Enrich.WithProperty("App", hostEnvironment.ApplicationName)
.Enrich.WithProperty("Env", hostEnvironment.EnvironmentName)
.MinimumLevel.Information()
.MinimumLevel.Is(LogEventLevel.Information)
.WriteTo.Trace()
.WriteTo.Console()
.WriteTo.ApplicationInsights(TelemetryConfiguration.CreateDefault(), TelemetryConverter.Traces);
Expand All @@ -61,6 +59,12 @@ public static LoggerConfiguration ConfigureLogging(LoggerConfiguration loggerCon
{
foreach(IConfigurationSection child in logLevelConfig.GetChildren())
{
if (child.Key == "Default")
{
loggerConfiguration.MinimumLevel.Is(logLevelConfig.GetValue<LogEventLevel>(child.Key));
continue;
}

loggerConfiguration.MinimumLevel.Override(child.Key, logLevelConfig.GetValue<LogEventLevel>(child.Key));
}
}
Expand Down

0 comments on commit 54cdfa8

Please sign in to comment.