From a2018842b70280a0336bc9c3be2bc26c68217b3d Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Thu, 5 Apr 2018 12:23:26 +1000 Subject: [PATCH] Added tests from #91 comments --- .../ConfigurationSettingsTests.cs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs index 5a627a7..bdb5c6a 100644 --- a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs @@ -390,5 +390,73 @@ public void LoggingLevelSwitchCanBeUsedForMinimumLevelOverrides() Assert.False(evt is null, "LoggingLevelSwitch level was changed to Information for logger System.*. It should now log Information events for SourceContext System.Bar."); // ReSharper restore HeuristicUnreachableCode } + + + [Trait("Bugfix", "#91")] + [Fact] + public void WriteToLoggerWithRestrictedToMinimumLevelIsSupported() + { + var json = @"{ + ""Serilog"": { + ""Using"": [""TestDummies""], + ""WriteTo"": [{ + ""Name"": ""Logger"", + ""Args"": { + ""configureLogger"" : { + ""WriteTo"": [{ + ""Name"": ""DummyRollingFile"", + ""Args"": {""pathFormat"" : ""C:\\""} + }]}, + ""restrictedToMinimumLevel"": ""Warning"" + } + }] + } + }"; + + var log = ConfigFromJson(json) + .CreateLogger(); + + DummyRollingFileSink.Emitted.Clear(); + + log.Write(Some.InformationEvent()); + log.Write(Some.WarningEvent()); + + Assert.Equal(1, DummyRollingFileSink.Emitted.Count); + } + + [Trait("Bugfix", "#91")] + [Fact] + public void WriteToSubLoggerWithLevelSwitchIsSupported() + { + var json = @"{ + ""Serilog"": { + ""Using"": [""TestDummies""], + ""LevelSwitches"": {""$switch1"" : ""Warning"" }, + ""MinimumLevel"" : { + ""ControlledBy"" : ""$switch1"" + }, + ""WriteTo"": [{ + ""Name"": ""Logger"", + ""Args"": { + ""configureLogger"" : { + ""WriteTo"": [{ + ""Name"": ""DummyRollingFile"", + ""Args"": {""pathFormat"" : ""C:\\""} + }]} + } + }] + } + }"; + + var log = ConfigFromJson(json) + .CreateLogger(); + + DummyRollingFileSink.Emitted.Clear(); + + log.Write(Some.InformationEvent()); + log.Write(Some.WarningEvent()); + + Assert.Equal(1, DummyRollingFileSink.Emitted.Count); + } } }