From e0ca4636eac212162609acc51d4bac6940f08375 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Fri, 6 Jan 2023 14:44:51 +0300 Subject: [PATCH] Small cleanup --- README.md | 2 +- .../Serilog.Settings.Configuration.csproj | 6 +- .../DynamicLevelChangeTests.cs | 69 +++++++++---------- 3 files changed, 36 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 6085e4d..8d3e8fd 100644 --- a/README.md +++ b/README.md @@ -226,7 +226,7 @@ This section defines a static list of key-value pairs that will enrich log event ### Filter section -This section defines filters that will be applied to log events. It is especially usefull in combination with _[Serilog.Expressions](https://github.com/serilog/serilog-expressions)_ (or legacy _[Serilog.Filters.Expressions](https://github.com/serilog/serilog-filters-expressions)_) package so you can write expression in text form: +This section defines filters that will be applied to log events. It is especially useful in combination with _[Serilog.Expressions](https://github.com/serilog/serilog-expressions)_ (or legacy _[Serilog.Filters.Expressions](https://github.com/serilog/serilog-filters-expressions)_) package so you can write expression in text form: ```yaml "Filter": [{ diff --git a/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj b/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj index c12d61d..a2d8160 100644 --- a/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj +++ b/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj @@ -3,19 +3,15 @@ Microsoft.Extensions.Configuration (appsettings.json) support for Serilog. 3.5.0 - latest Serilog Contributors netstandard2.0;net451;net461 - true true Serilog.Settings.Configuration ../../assets/Serilog.snk true true - Serilog.Settings.Configuration serilog;json icon.png - https://github.com/serilog/serilog-settings-configuration/ Apache-2.0 Serilog true @@ -28,7 +24,7 @@ - + diff --git a/test/Serilog.Settings.Configuration.Tests/DynamicLevelChangeTests.cs b/test/Serilog.Settings.Configuration.Tests/DynamicLevelChangeTests.cs index 8df43fb..1c3eb5a 100644 --- a/test/Serilog.Settings.Configuration.Tests/DynamicLevelChangeTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/DynamicLevelChangeTests.cs @@ -45,43 +45,42 @@ public DynamicLevelChangeTests() [Fact] public void ShouldRespectDynamicLevelChanges() { - using (var logger = new LoggerConfiguration() + using var logger = new LoggerConfiguration() .ReadFrom .Configuration(new ConfigurationBuilder().Add(_configSource).Build()) - .CreateLogger()) - { - DummyConsoleSink.Emitted.Clear(); - logger.Write(Some.DebugEvent()); - Assert.Empty(DummyConsoleSink.Emitted); - - DummyConsoleSink.Emitted.Clear(); - UpdateConfig(minimumLevel: LogEventLevel.Debug); - logger.Write(Some.DebugEvent()); - Assert.Empty(DummyConsoleSink.Emitted); - - DummyConsoleSink.Emitted.Clear(); - UpdateConfig(switchLevel: LogEventLevel.Debug); - logger.Write(Some.DebugEvent()); - logger.ForContext(Constants.SourceContextPropertyName, "Root.Test").Write(Some.DebugEvent()); - Assert.Single(DummyConsoleSink.Emitted); - - DummyConsoleSink.Emitted.Clear(); - UpdateConfig(overrideLevel: LogEventLevel.Debug); - logger.ForContext(Constants.SourceContextPropertyName, "Root.Test").Write(Some.DebugEvent()); - Assert.Single(DummyConsoleSink.Emitted); - - DummyConsoleSink.Emitted.Clear(); - UpdateConfig(filterExpression: "Prop = 'Val_1'"); - logger.Write(Some.DebugEvent()); - logger.ForContext("Prop", "Val_1").Write(Some.DebugEvent()); - Assert.Single(DummyConsoleSink.Emitted); - - DummyConsoleSink.Emitted.Clear(); - UpdateConfig(filterExpression: "Prop = 'Val_2'"); - logger.Write(Some.DebugEvent()); - logger.ForContext("Prop", "Val_1").Write(Some.DebugEvent()); - Assert.Empty(DummyConsoleSink.Emitted); - } + .CreateLogger(); + + DummyConsoleSink.Emitted.Clear(); + logger.Write(Some.DebugEvent()); + Assert.Empty(DummyConsoleSink.Emitted); + + DummyConsoleSink.Emitted.Clear(); + UpdateConfig(minimumLevel: LogEventLevel.Debug); + logger.Write(Some.DebugEvent()); + Assert.Empty(DummyConsoleSink.Emitted); + + DummyConsoleSink.Emitted.Clear(); + UpdateConfig(switchLevel: LogEventLevel.Debug); + logger.Write(Some.DebugEvent()); + logger.ForContext(Constants.SourceContextPropertyName, "Root.Test").Write(Some.DebugEvent()); + Assert.Single(DummyConsoleSink.Emitted); + + DummyConsoleSink.Emitted.Clear(); + UpdateConfig(overrideLevel: LogEventLevel.Debug); + logger.ForContext(Constants.SourceContextPropertyName, "Root.Test").Write(Some.DebugEvent()); + Assert.Single(DummyConsoleSink.Emitted); + + DummyConsoleSink.Emitted.Clear(); + UpdateConfig(filterExpression: "Prop = 'Val_1'"); + logger.Write(Some.DebugEvent()); + logger.ForContext("Prop", "Val_1").Write(Some.DebugEvent()); + Assert.Single(DummyConsoleSink.Emitted); + + DummyConsoleSink.Emitted.Clear(); + UpdateConfig(filterExpression: "Prop = 'Val_2'"); + logger.Write(Some.DebugEvent()); + logger.ForContext("Prop", "Val_1").Write(Some.DebugEvent()); + Assert.Empty(DummyConsoleSink.Emitted); } void UpdateConfig(LogEventLevel? minimumLevel = null, LogEventLevel? switchLevel = null, LogEventLevel? overrideLevel = null, string filterExpression = null)