Skip to content

8.0.0 Release #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,4 @@ FakesAssemblies/
project.lock.json

artifacts/
/test/TestApp-*
7 changes: 2 additions & 5 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ if($LASTEXITCODE -ne 0) { throw 'pack failed' }

Write-Output "build: Testing"

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

if($LASTEXITCODE -ne 0) { throw 'unit tests failed' }
if($LASTEXITCODE -ne 0) { throw 'unit tests failed' }
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,74 @@ Some Serilog packages require a reference to a logger configuration object. The
},
```

### Destructuring

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:

```yaml
"Destructure": [
{
"Name": "With",
"Args": {
"policy": "MyFirstNamespace.FirstDestructuringPolicy, MyFirstAssembly"
}
},
{
"Name": "With",
"Args": {
"policy": "policy": "MySecondNamespace.SecondDestructuringPolicy, MySecondAssembly"
}
},
{
"Name": "With",
"Args": {
"policy": "policy": "MyThirdNamespace.ThirdDestructuringPolicy, MyThirdAssembly"
}
},
],
```

This is how the first destructuring policy would look like:

```csharp
namespace MyFirstNamespace;

public record MyDto(int Id, int Name);

public class FirstDestructuringPolicy : IDestructuringPolicy
{
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory,
[NotNullWhen(true)] out LogEventPropertyValue? result)
{
if (value is not MyDto dto)
{
result = null;
return false;
}

result = new StructureValue(new List<LogEventProperty>
{
new LogEventProperty("Identifier", new ScalarValue(deleteTodoItemInfo.Id)),
new LogEventProperty("NormalizedName", new ScalarValue(dto.Name.ToUpperInvariant()))
});

return true;
}
}
```

Assuming Serilog needs to destructure an argument of type **MyDto** when handling a log event:

```csharp
logger.Information("About to process input: {@MyDto} ...", myDto);
```

it will apply **FirstDestructuringPolicy** which will convert **MyDto** instance to a **StructureValue** instance; a Serilog console sink would write the following entry:

```text
About to process input: {"Identifier": 191, "NormalizedName": "SOME_UPPER_CASE_NAME"} ...
```

## Arguments binding

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.
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ artifacts:
deploy:
- provider: NuGet
api_key:
secure: 60gpLnipFCiKLpS7ECI1C6EPJW27KzVwqrBVkEzX6FIMTmsG//HD3p8Oq7WdQPm8
secure: JIfNMRv3l/2dmM/i//mpeEKqgxyEcnGr8XFlEoSDgp2JDVmRP8nUxc4gYznBvXQV
on:
branch: /^(main|dev)$/
OS: Windows_NT
Expand Down
4 changes: 1 addition & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"sdk": {
"version": "7.0.201",
"allowPrerelease": false,
"rollForward": "latestFeature"
"version": "8.0.100"
}
}
14 changes: 7 additions & 7 deletions sample/Sample/Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net462</TargetFrameworks>
<TargetFrameworks>net462;net6.0;net7.0;net8.0</TargetFrameworks>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand All @@ -14,15 +14,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageReference Include="Serilog.Expressions" Version="3.3.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.3.0" />
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="PolySharp" Version="1.13.1" PrivateAssets="all" />
<PackageReference Include="PolySharp" Version="1.13.2" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
<PropertyGroup>
<Description>Microsoft.Extensions.Configuration (appsettings.json) support for Serilog.</Description>
<!-- This must match the major and minor components of the referenced Microsoft.Extensions.Logging package. -->
<VersionPrefix>7.0.1</VersionPrefix>
<VersionPrefix>8.0.0</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<!-- These must match the Dependencies tab in https://www.nuget.org/packages/microsoft.settings.configuration at
the target version. -->
<TargetFrameworks>net462;netstandard2.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net462;netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Serilog.Settings.Configuration</AssemblyName>
<PackageTags>serilog;json</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/serilog/serilog-settings-configuration</PackageProjectUrl>
<PackageReleaseNotes>$(PackageProjectUrl)/releases</PackageReleaseNotes>
<RootNamespace>Serilog</RootNamespace>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand All @@ -26,14 +29,15 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="PolySharp" Version="1.13.1" PrivateAssets="All" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="PolySharp" Version="1.13.2" PrivateAssets="All" />
<PackageReference Include="Serilog" Version="3.1.1" />
<None Include="..\..\assets\icon.png" Pack="true" PackagePath="" Visible="false" />
<None Include="..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<!-- The versions of all references in this group must match the major and minor components of the package version prefix. -->
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,12 @@ public void TestMinimumLevelOverridesForChildContext()
log.Write(Some.DebugEvent());
Assert.Null(evt);

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

evt = null;
var systemThreadingLogger = log.ForContext<System.Threading.Tasks.Task>();
var systemThreadingLogger = log.ForContext<Task>();
systemThreadingLogger.Write(Some.DebugEvent());
Assert.NotNull(evt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@ namespace Serilog.Settings.Configuration.Tests;

public class DllScanningAssemblyFinderTests
{
#if NETFRAMEWORK
const string BinDir1 = "bin1";
const string BinDir2 = "bin2";
const string BinDir3 = "bin3";

[Fact]
public void ShouldProbeCurrentDirectory()
{
var assemblyNames = new DllScanningAssemblyFinder().FindAssembliesContainingName("TestDummies");
Assert.Single(assemblyNames);
}

#if NETFRAMEWORK
[Fact]
public void ShouldProbePrivateBinPath()
{
Expand Down Expand Up @@ -61,4 +54,11 @@ static void DoTestInner()
}
}
#endif

[Fact]
public void ShouldProbeCurrentDirectory()
{
var assemblyNames = new DllScanningAssemblyFinder().FindAssembliesContainingName("TestDummies");
Assert.Single(assemblyNames);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net48</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,16 +17,16 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CliWrap" Version="3.6.0" />
<PackageReference Include="FluentAssertions" Version="6.10.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NuGet.Frameworks" Version="6.5.0" />
<PackageReference Include="Polly" Version="7.2.3" />
<PackageReference Include="Serilog.Expressions" Version="3.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="CliWrap" Version="3.6.4" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NuGet.Frameworks" Version="6.7.0" />
<PackageReference Include="Polly" Version="8.2.0" />
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
</ItemGroup>

Expand Down
5 changes: 3 additions & 2 deletions test/TestApp/TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PublishReferencesDocumentationFiles>false</PublishReferencesDocumentationFiles>
<AllowedReferenceRelatedFileExtensions>none</AllowedReferenceRelatedFileExtensions>
<UseCurrentRuntimeIdentifier>true</UseCurrentRuntimeIdentifier>
<SelfContained>true</SelfContained>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="Costura.Fody" Version="5.7.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion test/TestDummies/DummyPolicy.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Serilog.Core;
using Serilog.Events;
using System.Collections;
using System.Diagnostics.CodeAnalysis;

namespace TestDummies;

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

public decimal Decimal { get; set; }

public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue? result)
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result)
{
result = null;
return false;
Expand Down
5 changes: 3 additions & 2 deletions test/TestDummies/TestDummies.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down