diff --git a/README.md b/README.md index f2f2630..5ea2c23 100644 --- a/README.md +++ b/README.md @@ -288,7 +288,7 @@ var logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration, options) .CreateLogger(); -ILoggingFilterSwitch filterSwitch = filterSwitches["$filterSwitch"]; +ILoggingFilterSwitch filterSwitch = filterSwitches["filterSwitch"]; ``` ### Nested configuration sections diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs index 67459d2..2a6c317 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs @@ -75,8 +75,8 @@ void ProcessFilterSwitchDeclarations() SetFilterSwitch(throwOnError: true); SubscribeToFilterExpressionChanges(); - var referenceName = _resolutionContext.AddFilterSwitch(switchName, filterSwitch); - _resolutionContext.ReaderOptions.OnFilterSwitchCreated?.Invoke(referenceName, filterSwitch); + _resolutionContext.AddFilterSwitch(switchName, filterSwitch); + _resolutionContext.ReaderOptions.OnFilterSwitchCreated?.Invoke(switchName, filterSwitch); void SubscribeToFilterExpressionChanges() { diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReaderOptions.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReaderOptions.cs index d0696a6..4510aa9 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReaderOptions.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReaderOptions.cs @@ -79,7 +79,6 @@ public ConfigurationReaderOptions() : this(dependencyContext: null) /// /// Called when a log filter switch is created while reading the Serilog:FilterSwitches section of the configuration. - /// The switch name includes the leading $ character. /// public Action? OnFilterSwitchCreated { get; init; } diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ResolutionContext.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ResolutionContext.cs index d002620..61d40d8 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ResolutionContext.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ResolutionContext.cs @@ -62,13 +62,12 @@ public string AddLevelSwitch(string levelSwitchName, LoggingLevelSwitch levelSwi return referenceName; } - public string AddFilterSwitch(string filterSwitchName, LoggingFilterSwitchProxy filterSwitch) + public void AddFilterSwitch(string filterSwitchName, LoggingFilterSwitchProxy filterSwitch) { if (filterSwitchName == null) throw new ArgumentNullException(nameof(filterSwitchName)); if (filterSwitch == null) throw new ArgumentNullException(nameof(filterSwitch)); var referenceName = ToSwitchReference(filterSwitchName); _declaredFilterSwitches[referenceName] = filterSwitch; - return referenceName; } string ToSwitchReference(string switchName) diff --git a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs index 23f41e2..4916f35 100644 --- a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs @@ -1548,19 +1548,16 @@ public void TestLogLevelSwitchesCallback(string switchName) Assert.Equal(LogEventLevel.Debug, systemThreading.MinimumLevel); } - [Theory] - [InlineData("$switch1", "$switch2")] - [InlineData("$switch1", "switch2")] - [InlineData("switch1", "$switch2")] - [InlineData("switch1", "switch2")] - public void TestLogFilterSwitchesCallback(string switch1Name, string switch2Name) + [Fact] + public void TestLogFilterSwitchesCallback() { - var json = $$""" + // language=json + var json = """ { - 'Serilog': { - 'FilterSwitches': { - '{{switch1Name}}': 'Prop = 1', - '{{switch2Name}}': 'Prop = 2' + "Serilog": { + "FilterSwitches": { + "switch1": "Prop = 1", + "$switch2": "Prop = 2" } } } @@ -1572,7 +1569,7 @@ public void TestLogFilterSwitchesCallback(string switch1Name, string switch2Name Assert.Equal(2, switches.Count); - var switch1 = Assert.Contains("$switch1", switches); + var switch1 = Assert.Contains("switch1", switches); Assert.Equal("Prop = 1", switch1.Expression); var switch2 = Assert.Contains("$switch2", switches);