From 322c2f9522d9bedff289e6e4257e730a2f7a945a Mon Sep 17 00:00:00 2001 From: "dzmitry.lahoda" Date: Fri, 3 May 2019 17:34:39 +0300 Subject: [PATCH 1/3] added test to show how to filter child contexts --- .../ConfigurationSettingsTests.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs index ea9357e..3b21d9c 100644 --- a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs @@ -194,6 +194,39 @@ public void TestMinimumLevelOverrides() Assert.NotNull(evt); } + [Fact] + public void TestMinimumLevelOverridesForChildContext() + { + var json = @"{ + ""Serilog"": { + ""MinimumLevel"" : { + ""Default"" : ""Warning"", + ""Override"" : { + ""System"" : ""Warning"", + ""System.Threading"": ""Debug"" + } + } + } + }"; + + LogEvent evt = null; + + var log = ConfigFromJson(json) + .WriteTo.Sink(new DelegatingSink(e => evt = e)) + .CreateLogger(); + + log.Write(Some.DebugEvent()); + Assert.Null(evt); + + var custom = log.ForContext("SourceContext", "System.Threading.Tasks.Task<42>"); + custom.Write(Some.DebugEvent()); + Assert.NotNull(evt); + + var systemThreadingLogger = log.ForContext(); + systemThreadingLogger.Write(Some.DebugEvent()); + Assert.NotNull(evt); + } + [Fact] public void SinksWithAbstractParamsAreConfiguredWithTypeName() { From 8232f74104d74adad8cac26ba09e70a9633e0807 Mon Sep 17 00:00:00 2001 From: "dzmitry.lahoda" Date: Fri, 3 May 2019 17:51:21 +0300 Subject: [PATCH 2/3] ensure null --- .../ConfigurationSettingsTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs index 3b21d9c..161b810 100644 --- a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs @@ -221,7 +221,8 @@ public void TestMinimumLevelOverridesForChildContext() var custom = log.ForContext("SourceContext", "System.Threading.Tasks.Task<42>"); custom.Write(Some.DebugEvent()); Assert.NotNull(evt); - + + evt = null; var systemThreadingLogger = log.ForContext(); systemThreadingLogger.Write(Some.DebugEvent()); Assert.NotNull(evt); From 3ae1b9ff5fd3fa2bbfa2a2c45ad2fd61c641b178 Mon Sep 17 00:00:00 2001 From: "dzmitry.lahoda" Date: Fri, 3 May 2019 17:56:13 +0300 Subject: [PATCH 3/3] used more constants --- .../ConfigurationSettingsTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs index 161b810..eed3803 100644 --- a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs @@ -218,7 +218,7 @@ public void TestMinimumLevelOverridesForChildContext() log.Write(Some.DebugEvent()); Assert.Null(evt); - var custom = log.ForContext("SourceContext", "System.Threading.Tasks.Task<42>"); + var custom = log.ForContext(Constants.SourceContextPropertyName, typeof(System.Threading.Tasks.Task).FullName + "<42>"); custom.Write(Some.DebugEvent()); Assert.NotNull(evt);