Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer "MinimumLevel:Default" value if "MinimumLevel" value returns empty string #413

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ void ApplyMinimumLevelConfiguration(IConfigurationSection directive, Action<Logg
{
foreach (var provider in _configurationRoot.Providers.Reverse())
{
if (provider.TryGet(minimumLevelDirective.Path, out _))
if (provider.TryGet(minimumLevelDirective.Path, out var minValue) && !string.IsNullOrEmpty(minValue))
{
return _configurationRoot.GetSection(minimumLevelDirective.Path);
}

if (provider.TryGet(defaultLevelDirective.Path, out _))
if (provider.TryGet(defaultLevelDirective.Path, out var defaultValue) && !string.IsNullOrEmpty(defaultValue))
{
return _configurationRoot.GetSection(defaultLevelDirective.Path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,23 @@ public void ReadFromConfigurationSectionDoesNotThrowWhenTryingToCallConfiguratio
.CreateLogger();

}

[Fact]
[Trait("BugFix", "https://github.com/serilog/serilog-settings-configuration/issues/332")]
public void ReadFromConfigurationThrowsWhenMinimumLevelDefaultSetButMinimumLevelValueIsEmptyString()
DavidAllardyce marked this conversation as resolved.
Show resolved Hide resolved
{
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string?>
{
["Serilog"] = "",
["Serilog:MinimumLevel"] = "",
["Serilog:MinimumLevel:Default"] = "Information",

})
.Build();

new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
}
}