Skip to content

Commit

Permalink
Merge pull request #344 from sungam3r/temp
Browse files Browse the repository at this point in the history
Small cleanup
  • Loading branch information
skomis-mm authored Jan 6, 2023
2 parents 99b9ed1 + e0ca463 commit ab87641
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
<PropertyGroup>
<Description>Microsoft.Extensions.Configuration (appsettings.json) support for Serilog.</Description>
<VersionPrefix>3.5.0</VersionPrefix>
<LangVersion>latest</LangVersion>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks>netstandard2.0;net451;net461</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Serilog.Settings.Configuration</AssemblyName>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>Serilog.Settings.Configuration</PackageId>
<PackageTags>serilog;json</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/serilog/serilog-settings-configuration/</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RootNamespace>Serilog</RootNamespace>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand All @@ -28,7 +24,7 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="3.0.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<None Include="..\..\assets\icon.png" Pack="true" PackagePath="" />
<None Include="..\..\assets\icon.png" Pack="true" PackagePath="" Visible="false" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net451'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ab87641

Please sign in to comment.