diff --git a/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs b/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs index 5e28936c6..602eedffa 100644 --- a/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs +++ b/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs @@ -294,6 +294,8 @@ public static LoggerConfiguration AppSettings( this LoggerSettingsConfiguration settingConfiguration, string settingPrefix = "serilog") { if (settingConfiguration == null) throw new ArgumentNullException(nameof(settingConfiguration)); + if (settingPrefix == null) throw new ArgumentNullException(nameof(settingPrefix)); + if (settingPrefix.Contains(":")) throw new ArgumentException("Custom setting prefixes cannot contain the colon (:) character."); return settingConfiguration.Settings(new AppSettingsSettings(settingPrefix)); } #endif diff --git a/src/Serilog/Sinks/PeriodicBatching/PortableTimer.cs b/src/Serilog/Sinks/PeriodicBatching/PortableTimer.cs index ce403b865..f54de2e75 100644 --- a/src/Serilog/Sinks/PeriodicBatching/PortableTimer.cs +++ b/src/Serilog/Sinks/PeriodicBatching/PortableTimer.cs @@ -55,7 +55,7 @@ public async void Start(TimeSpan interval) // current API, which allows the tick handler to reenter and set the next interval. if (_state == PortableTimerState.Waiting) - throw new InvalidOperationException("The timer is already set"); + throw new InvalidOperationException("The timer is already set."); if (_cancel.IsCancellationRequested) return; diff --git a/test/Serilog.Tests/Settings/AppSettingsTests.cs b/test/Serilog.Tests/Settings/AppSettingsTests.cs index 318dfa107..2e14c8664 100644 --- a/test/Serilog.Tests/Settings/AppSettingsTests.cs +++ b/test/Serilog.Tests/Settings/AppSettingsTests.cs @@ -1,4 +1,5 @@ #if !DNXCORE50 +using System; using System.Configuration; using Xunit; using Serilog.Events; @@ -30,8 +31,8 @@ public void EnvironmentVariableExpansionIsApplied() [Fact] public void CanUseCustomPrefixToConfigureSettings() { - const string prefix1 = "custom1:serilog"; - const string prefix2 = "custom2:serilog"; + const string prefix1 = "custom1-serilog"; + const string prefix2 = "custom2-serilog"; // Make sure we have the expected keys in the App.config Assert.Equal("Warning", ConfigurationManager.AppSettings[prefix1 + ":minimum-level"]); @@ -51,6 +52,13 @@ public void CanUseCustomPrefixToConfigureSettings() Assert.False(log2.IsEnabled(LogEventLevel.Warning)); Assert.True(log2.IsEnabled(LogEventLevel.Error)); } + + [Fact] + public void CustomPrefixCannotContainColon() + { + Assert.Throws(() => + new LoggerConfiguration().ReadFrom.AppSettings("custom1:serilog")); + } } } #endif diff --git a/test/Serilog.Tests/app.config b/test/Serilog.Tests/app.config index 346514b7e..a864cba68 100644 --- a/test/Serilog.Tests/app.config +++ b/test/Serilog.Tests/app.config @@ -2,7 +2,7 @@ - - + + \ No newline at end of file