Skip to content

Commit 014b42c

Browse files
authored
Merge pull request #402 from serilog/dev
8.0.0 Release
2 parents 2846a75 + 717a458 commit 014b42c

13 files changed

+119
-48
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,4 @@ FakesAssemblies/
201201
project.lock.json
202202

203203
artifacts/
204+
/test/TestApp-*

Diff for: Build.ps1

+2-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ if($LASTEXITCODE -ne 0) { throw 'pack failed' }
3030

3131
Write-Output "build: Testing"
3232

33-
# Dotnet test doesn't run separate TargetFrameworks in parallel: https://github.com/dotnet/sdk/issues/19147
34-
# Workaround: use `dotnet test` on dlls directly in order to pass the `--parallel` option to vstest.
35-
# The _reported_ runtime is wrong but the _actual_ used runtime is correct, see https://github.com/microsoft/vstest/issues/2037#issuecomment-720549173
36-
& dotnet test test\Serilog.Settings.Configuration.Tests\bin\Release\*\Serilog.Settings.Configuration.Tests.dll --parallel
33+
& dotnet test test\Serilog.Settings.Configuration.Tests\Serilog.Settings.Configuration.Tests.csproj
3734

38-
if($LASTEXITCODE -ne 0) { throw 'unit tests failed' }
35+
if($LASTEXITCODE -ne 0) { throw 'unit tests failed' }

Diff for: README.md

+68
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,74 @@ Some Serilog packages require a reference to a logger configuration object. The
313313
},
314314
```
315315

316+
### Destructuring
317+
318+
Destructuring means extracting pieces of information from an object and create properties with values; Serilog offers the `@` [structure-capturing operator](https://github.com/serilog/serilog/wiki/Structured-Data#preserving-object-structure). In case there is a need to customize the way log events are serialized (e.g., hide property values or replace them with something else), one can define several destructuring policies, like this:
319+
320+
```yaml
321+
"Destructure": [
322+
{
323+
"Name": "With",
324+
"Args": {
325+
"policy": "MyFirstNamespace.FirstDestructuringPolicy, MyFirstAssembly"
326+
}
327+
},
328+
{
329+
"Name": "With",
330+
"Args": {
331+
"policy": "policy": "MySecondNamespace.SecondDestructuringPolicy, MySecondAssembly"
332+
}
333+
},
334+
{
335+
"Name": "With",
336+
"Args": {
337+
"policy": "policy": "MyThirdNamespace.ThirdDestructuringPolicy, MyThirdAssembly"
338+
}
339+
},
340+
],
341+
```
342+
343+
This is how the first destructuring policy would look like:
344+
345+
```csharp
346+
namespace MyFirstNamespace;
347+
348+
public record MyDto(int Id, int Name);
349+
350+
public class FirstDestructuringPolicy : IDestructuringPolicy
351+
{
352+
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory,
353+
[NotNullWhen(true)] out LogEventPropertyValue? result)
354+
{
355+
if (value is not MyDto dto)
356+
{
357+
result = null;
358+
return false;
359+
}
360+
361+
result = new StructureValue(new List<LogEventProperty>
362+
{
363+
new LogEventProperty("Identifier", new ScalarValue(deleteTodoItemInfo.Id)),
364+
new LogEventProperty("NormalizedName", new ScalarValue(dto.Name.ToUpperInvariant()))
365+
});
366+
367+
return true;
368+
}
369+
}
370+
```
371+
372+
Assuming Serilog needs to destructure an argument of type **MyDto** when handling a log event:
373+
374+
```csharp
375+
logger.Information("About to process input: {@MyDto} ...", myDto);
376+
```
377+
378+
it will apply **FirstDestructuringPolicy** which will convert **MyDto** instance to a **StructureValue** instance; a Serilog console sink would write the following entry:
379+
380+
```text
381+
About to process input: {"Identifier": 191, "NormalizedName": "SOME_UPPER_CASE_NAME"} ...
382+
```
383+
316384
## Arguments binding
317385

318386
When the configuration specifies a discrete value for a parameter (such as a string literal), the package will attempt to convert that value to the target method's declared CLR type of the parameter. Additional explicit handling is provided for parsing strings to `Uri`, `TimeSpan`, `enum`, arrays and custom collections.

Diff for: appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ artifacts:
3636
deploy:
3737
- provider: NuGet
3838
api_key:
39-
secure: 60gpLnipFCiKLpS7ECI1C6EPJW27KzVwqrBVkEzX6FIMTmsG//HD3p8Oq7WdQPm8
39+
secure: JIfNMRv3l/2dmM/i//mpeEKqgxyEcnGr8XFlEoSDgp2JDVmRP8nUxc4gYznBvXQV
4040
on:
4141
branch: /^(main|dev)$/
4242
OS: Windows_NT

Diff for: global.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"sdk": {
3-
"version": "7.0.201",
4-
"allowPrerelease": false,
5-
"rollForward": "latestFeature"
3+
"version": "8.0.100"
64
}
75
}

Diff for: sample/Sample/Sample.csproj

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0;net462</TargetFrameworks>
4+
<TargetFrameworks>net462;net6.0;net7.0;net8.0</TargetFrameworks>
55
<OutputType>Exe</OutputType>
66
</PropertyGroup>
77

@@ -14,15 +14,15 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
1818
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
19-
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
19+
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
2020
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
21-
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
22-
<PackageReference Include="Serilog.Expressions" Version="3.3.0" />
23-
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
21+
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.3.0" />
22+
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
23+
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
2424
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
25-
<PackageReference Include="PolySharp" Version="1.13.1" PrivateAssets="all" />
25+
<PackageReference Include="PolySharp" Version="1.13.2" PrivateAssets="all" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

Diff for: src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
<PropertyGroup>
44
<Description>Microsoft.Extensions.Configuration (appsettings.json) support for Serilog.</Description>
55
<!-- This must match the major and minor components of the referenced Microsoft.Extensions.Logging package. -->
6-
<VersionPrefix>7.0.1</VersionPrefix>
6+
<VersionPrefix>8.0.0</VersionPrefix>
77
<Authors>Serilog Contributors</Authors>
88
<!-- These must match the Dependencies tab in https://www.nuget.org/packages/microsoft.settings.configuration at
99
the target version. -->
10-
<TargetFrameworks>net462;netstandard2.0;net6.0;net7.0</TargetFrameworks>
10+
<TargetFrameworks>net462;netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
1111
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1212
<AssemblyName>Serilog.Settings.Configuration</AssemblyName>
1313
<PackageTags>serilog;json</PackageTags>
1414
<PackageIcon>icon.png</PackageIcon>
15+
<PackageReadmeFile>README.md</PackageReadmeFile>
1516
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
17+
<PackageProjectUrl>https://github.com/serilog/serilog-settings-configuration</PackageProjectUrl>
18+
<PackageReleaseNotes>$(PackageProjectUrl)/releases</PackageReleaseNotes>
1619
<RootNamespace>Serilog</RootNamespace>
1720
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1821
<EmbedUntrackedSources>true</EmbedUntrackedSources>
@@ -26,14 +29,15 @@
2629

2730
<ItemGroup>
2831
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
29-
<PackageReference Include="PolySharp" Version="1.13.1" PrivateAssets="All" />
30-
<PackageReference Include="Serilog" Version="2.12.0" />
32+
<PackageReference Include="PolySharp" Version="1.13.2" PrivateAssets="All" />
33+
<PackageReference Include="Serilog" Version="3.1.1" />
3134
<None Include="..\..\assets\icon.png" Pack="true" PackagePath="" Visible="false" />
35+
<None Include="..\..\README.md" Pack="true" PackagePath="" />
3236
</ItemGroup>
3337

3438
<ItemGroup>
3539
<!-- The versions of all references in this group must match the major and minor components of the package version prefix. -->
36-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
37-
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
40+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
41+
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.0" />
3842
</ItemGroup>
3943
</Project>

Diff for: test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,12 @@ public void TestMinimumLevelOverridesForChildContext()
395395
log.Write(Some.DebugEvent());
396396
Assert.Null(evt);
397397

398-
var custom = log.ForContext(Constants.SourceContextPropertyName, typeof(System.Threading.Tasks.Task).FullName + "<42>");
398+
var custom = log.ForContext(Constants.SourceContextPropertyName, typeof(Task).FullName + "<42>");
399399
custom.Write(Some.DebugEvent());
400400
Assert.NotNull(evt);
401401

402402
evt = null;
403-
var systemThreadingLogger = log.ForContext<System.Threading.Tasks.Task>();
403+
var systemThreadingLogger = log.ForContext<Task>();
404404
systemThreadingLogger.Write(Some.DebugEvent());
405405
Assert.NotNull(evt);
406406
}

Diff for: test/Serilog.Settings.Configuration.Tests/DllScanningAssemblyFinderTests.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,11 @@ namespace Serilog.Settings.Configuration.Tests;
99

1010
public class DllScanningAssemblyFinderTests
1111
{
12+
#if NETFRAMEWORK
1213
const string BinDir1 = "bin1";
1314
const string BinDir2 = "bin2";
1415
const string BinDir3 = "bin3";
1516

16-
[Fact]
17-
public void ShouldProbeCurrentDirectory()
18-
{
19-
var assemblyNames = new DllScanningAssemblyFinder().FindAssembliesContainingName("TestDummies");
20-
Assert.Single(assemblyNames);
21-
}
22-
23-
#if NETFRAMEWORK
2417
[Fact]
2518
public void ShouldProbePrivateBinPath()
2619
{
@@ -61,4 +54,11 @@ static void DoTestInner()
6154
}
6255
}
6356
#endif
57+
58+
[Fact]
59+
public void ShouldProbeCurrentDirectory()
60+
{
61+
var assemblyNames = new DllScanningAssemblyFinder().FindAssembliesContainingName("TestDummies");
62+
Assert.Single(assemblyNames);
63+
}
6464
}

Diff for: test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net48</TargetFrameworks>
5-
<TargetFrameworks>$(TargetFrameworks);net7.0;net6.0</TargetFrameworks>
5+
<TargetFrameworks>$(TargetFrameworks);net6.0;net7.0;net8.0</TargetFrameworks>
66
</PropertyGroup>
77

88
<ItemGroup>
@@ -17,16 +17,16 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="CliWrap" Version="3.6.0" />
21-
<PackageReference Include="FluentAssertions" Version="6.10.0" />
22-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
23-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
24-
<PackageReference Include="NuGet.Frameworks" Version="6.5.0" />
25-
<PackageReference Include="Polly" Version="7.2.3" />
26-
<PackageReference Include="Serilog.Expressions" Version="3.3.0" />
27-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
28-
<PackageReference Include="xunit" Version="2.4.2" />
29-
<PackageReference Include="Shouldly" Version="4.1.0" />
20+
<PackageReference Include="CliWrap" Version="3.6.4" />
21+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
22+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
23+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
24+
<PackageReference Include="NuGet.Frameworks" Version="6.7.0" />
25+
<PackageReference Include="Polly" Version="8.2.0" />
26+
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
27+
<PackageReference Include="xunit" Version="2.5.3" />
28+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
29+
<PackageReference Include="Shouldly" Version="4.2.1" />
3030
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
3131
</ItemGroup>
3232

Diff for: test/TestApp/TestApp.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<PublishReferencesDocumentationFiles>false</PublishReferencesDocumentationFiles>
1010
<AllowedReferenceRelatedFileExtensions>none</AllowedReferenceRelatedFileExtensions>
1111
<UseCurrentRuntimeIdentifier>true</UseCurrentRuntimeIdentifier>
12+
<SelfContained>true</SelfContained>
1213
</PropertyGroup>
1314

1415
<ItemGroup Condition="$(Configuration) == 'Debug'">
@@ -21,9 +22,9 @@
2122

2223
<ItemGroup>
2324
<PackageReference Include="Costura.Fody" Version="5.7.0" PrivateAssets="all" />
24-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
25+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
2526
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
26-
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
27+
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
2728
</ItemGroup>
2829

2930
</Project>

Diff for: test/TestDummies/DummyPolicy.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Serilog.Core;
22
using Serilog.Events;
33
using System.Collections;
4+
using System.Diagnostics.CodeAnalysis;
45

56
namespace TestDummies;
67

@@ -24,7 +25,7 @@ public class DummyPolicy : IDestructuringPolicy
2425

2526
public decimal Decimal { get; set; }
2627

27-
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue? result)
28+
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result)
2829
{
2930
result = null;
3031
return false;

Diff for: test/TestDummies/TestDummies.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Serilog" Version="2.10.0" />
8+
<PackageReference Include="Serilog" Version="3.1.1" />
9+
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" />
910
</ItemGroup>
1011

1112
<ItemGroup>
12-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
1314
</ItemGroup>
1415

1516
<ItemGroup>

0 commit comments

Comments
 (0)