diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs index 2a6c317..f994e25 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs @@ -164,7 +164,7 @@ void ApplyMinimumLevel(LoggerConfiguration loggerConfiguration) { var overridePrefix = overrideDirective.Key; var overridenLevelOrSwitch = overrideDirective.Value; - if (Enum.TryParse(overridenLevelOrSwitch, out LogEventLevel _)) + if (Enum.TryParse(overridenLevelOrSwitch, ignoreCase: true, out LogEventLevel _)) { ApplyMinimumLevelConfiguration(overrideDirective, (configuration, levelSwitch) => { @@ -221,7 +221,7 @@ void SubscribeToLoggingLevelChanges(IConfigurationSection levelSection, LoggingL levelSection.GetReloadToken, () => { - if (Enum.TryParse(levelSection.Value, out LogEventLevel minimumLevel)) + if (Enum.TryParse(levelSection.Value, ignoreCase: true, out LogEventLevel minimumLevel)) levelSwitch.MinimumLevel = minimumLevel; else SelfLog.WriteLine($"The value {levelSection.Value} is not a valid Serilog level."); @@ -591,9 +591,7 @@ internal static bool IsValidSwitchName(string input) } static LogEventLevel ParseLogEventLevel(string value) - { - if (!Enum.TryParse(value, ignoreCase: true, out LogEventLevel parsedLevel)) - throw new InvalidOperationException($"The value {value} is not a valid Serilog level."); - return parsedLevel; - } + => Enum.TryParse(value, ignoreCase: true, out LogEventLevel parsedLevel) + ? parsedLevel + : throw new InvalidOperationException($"The value {value} is not a valid Serilog level."); } diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/StringArgumentValue.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/StringArgumentValue.cs index ebf3d2e..2ba8dcc 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/StringArgumentValue.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/StringArgumentValue.cs @@ -10,7 +10,7 @@ class StringArgumentValue : IConfigurationArgumentValue { readonly string _providedValue; - static readonly Regex StaticMemberAccessorRegex = new Regex("^(?[^:]+)::(?[A-Za-z][A-Za-z0-9]*)(?[^:]*)$"); + static readonly Regex StaticMemberAccessorRegex = new("^(?[^:]+)::(?[A-Za-z][A-Za-z0-9]*)(?[^:]*)$"); public StringArgumentValue(string providedValue) {