Skip to content

Commit a201884

Browse files
committed
Added tests from #91 comments
1 parent e0ac44f commit a201884

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,5 +390,73 @@ public void LoggingLevelSwitchCanBeUsedForMinimumLevelOverrides()
390390
Assert.False(evt is null, "LoggingLevelSwitch level was changed to Information for logger System.*. It should now log Information events for SourceContext System.Bar.");
391391
// ReSharper restore HeuristicUnreachableCode
392392
}
393+
394+
395+
[Trait("Bugfix", "#91")]
396+
[Fact]
397+
public void WriteToLoggerWithRestrictedToMinimumLevelIsSupported()
398+
{
399+
var json = @"{
400+
""Serilog"": {
401+
""Using"": [""TestDummies""],
402+
""WriteTo"": [{
403+
""Name"": ""Logger"",
404+
""Args"": {
405+
""configureLogger"" : {
406+
""WriteTo"": [{
407+
""Name"": ""DummyRollingFile"",
408+
""Args"": {""pathFormat"" : ""C:\\""}
409+
}]},
410+
""restrictedToMinimumLevel"": ""Warning""
411+
}
412+
}]
413+
}
414+
}";
415+
416+
var log = ConfigFromJson(json)
417+
.CreateLogger();
418+
419+
DummyRollingFileSink.Emitted.Clear();
420+
421+
log.Write(Some.InformationEvent());
422+
log.Write(Some.WarningEvent());
423+
424+
Assert.Equal(1, DummyRollingFileSink.Emitted.Count);
425+
}
426+
427+
[Trait("Bugfix", "#91")]
428+
[Fact]
429+
public void WriteToSubLoggerWithLevelSwitchIsSupported()
430+
{
431+
var json = @"{
432+
""Serilog"": {
433+
""Using"": [""TestDummies""],
434+
""LevelSwitches"": {""$switch1"" : ""Warning"" },
435+
""MinimumLevel"" : {
436+
""ControlledBy"" : ""$switch1""
437+
},
438+
""WriteTo"": [{
439+
""Name"": ""Logger"",
440+
""Args"": {
441+
""configureLogger"" : {
442+
""WriteTo"": [{
443+
""Name"": ""DummyRollingFile"",
444+
""Args"": {""pathFormat"" : ""C:\\""}
445+
}]}
446+
}
447+
}]
448+
}
449+
}";
450+
451+
var log = ConfigFromJson(json)
452+
.CreateLogger();
453+
454+
DummyRollingFileSink.Emitted.Clear();
455+
456+
log.Write(Some.InformationEvent());
457+
log.Write(Some.WarningEvent());
458+
459+
Assert.Equal(1, DummyRollingFileSink.Emitted.Count);
460+
}
393461
}
394462
}

0 commit comments

Comments
 (0)