Skip to content

Commit e47a264

Browse files
committed
Merge branch 'dev' of https://github.com/serilog/serilog-extensions-logging into serilog-4x
2 parents 10afe06 + 1549fe5 commit e47a264

38 files changed

+666
-233
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# If this file is renamed, the incrementing run attempt number will be reset.
2+
3+
name: CI
4+
5+
on:
6+
push:
7+
branches: [ "dev", "main" ]
8+
pull_request:
9+
branches: [ "dev", "main" ]
10+
11+
env:
12+
CI_BUILD_NUMBER_BASE: ${{ github.run_number }}
13+
CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
14+
15+
jobs:
16+
build:
17+
18+
# The build must run on Windows so that .NET Framework targets can be built and tested.
19+
runs-on: windows-latest
20+
21+
permissions:
22+
contents: write
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Setup
27+
uses: actions/setup-dotnet@v4
28+
with:
29+
dotnet-version: 9.0.x
30+
- name: Compute build number
31+
shell: bash
32+
run: |
33+
echo "CI_BUILD_NUMBER=$(($CI_BUILD_NUMBER_BASE+2300))" >> $GITHUB_ENV
34+
- name: Build and Publish
35+
env:
36+
DOTNET_CLI_TELEMETRY_OPTOUT: true
37+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
38+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
shell: pwsh
40+
run: |
41+
./Build.ps1

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,7 @@ project.lock.json
200200
# JetBrains Rider
201201
.idea
202202

203-
.vscode
203+
.vscode
204+
205+
.DS_Store
206+

Build.ps1

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,79 @@
1-
echo "build: Build started"
1+
Write-Output "build: Tool versions follow"
22

3-
$env:Path = "$pwd/.dotnetcli;$env:Path"
3+
dotnet --version
4+
dotnet --list-sdks
5+
6+
Write-Output "build: Build started"
47

58
Push-Location $PSScriptRoot
9+
try {
10+
if(Test-Path .\artifacts) {
11+
Write-Output "build: Cleaning ./artifacts"
12+
Remove-Item ./artifacts -Force -Recurse
13+
}
614

7-
if(Test-Path .\artifacts) {
8-
echo "build: Cleaning .\artifacts"
9-
Remove-Item .\artifacts -Force -Recurse
10-
}
15+
& dotnet restore --no-cache
1116

12-
& dotnet restore --no-cache
17+
$dbp = [Xml] (Get-Content .\Directory.Version.props)
18+
$versionPrefix = $dbp.Project.PropertyGroup.VersionPrefix
1319

14-
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
15-
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
16-
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"]
20+
Write-Output "build: Package version prefix is $versionPrefix"
1721

18-
echo "build: Version suffix is $suffix"
22+
$branch = @{ $true = $env:CI_TARGET_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:CI_TARGET_BRANCH];
23+
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:CI_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:CI_BUILD_NUMBER];
24+
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '([^a-zA-Z0-9\-]*)', '')-$revision"}[$branch -eq "main" -and $revision -ne "local"]
25+
$commitHash = $(git rev-parse --short HEAD)
26+
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
1927

20-
foreach ($src in ls src/*) {
21-
Push-Location $src
28+
Write-Output "build: Package version suffix is $suffix"
29+
Write-Output "build: Build version suffix is $buildSuffix"
2230

23-
echo "build: Packaging project in $src"
31+
& dotnet build -c Release --version-suffix=$buildSuffix /p:ContinuousIntegrationBuild=true
32+
if($LASTEXITCODE -ne 0) { throw "Build failed" }
2433

25-
if($suffix) {
26-
& dotnet pack -c Release --include-source -o ..\..\artifacts --version-suffix=$suffix
27-
} else {
28-
& dotnet pack -c Release --include-source -o ..\..\artifacts
29-
}
34+
foreach ($src in Get-ChildItem src/*) {
35+
Push-Location $src
3036

31-
if($LASTEXITCODE -ne 0) { throw "build failed" }
37+
Write-Output "build: Packaging project in $src"
3238

33-
Pop-Location
34-
}
39+
if ($suffix) {
40+
& dotnet pack -c Release --no-build --no-restore -o ../../artifacts --version-suffix=$suffix
41+
} else {
42+
& dotnet pack -c Release --no-build --no-restore -o ../../artifacts
43+
}
44+
if($LASTEXITCODE -ne 0) { throw "Packaging failed" }
45+
46+
Pop-Location
47+
}
3548

36-
foreach ($test in ls test/*.PerformanceTests) {
37-
Push-Location $test
49+
foreach ($test in Get-ChildItem test/*.Tests) {
50+
Push-Location $test
3851

39-
echo "build: Building performance test project in $test"
52+
Write-Output "build: Testing project in $test"
4053

41-
& dotnet build -c Release
42-
if($LASTEXITCODE -ne 0) { throw "test failed" }
54+
& dotnet test -c Release --no-build --no-restore
55+
if($LASTEXITCODE -ne 0) { throw "Testing failed" }
4356

44-
Pop-Location
45-
}
57+
Pop-Location
58+
}
4659

47-
foreach ($test in ls test/*.Tests) {
48-
Push-Location $test
60+
if ($env:NUGET_API_KEY) {
61+
# GitHub Actions will only supply this to branch builds and not PRs. We publish
62+
# builds from any branch this action targets (i.e. main and dev).
4963

50-
echo "build: Testing project in $test"
64+
Write-Output "build: Publishing NuGet packages"
5165

52-
& dotnet test -c Release
53-
if($LASTEXITCODE -ne 0) { throw "test failed" }
66+
foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) {
67+
& dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg"
68+
if($LASTEXITCODE -ne 0) { throw "Publishing failed" }
69+
}
5470

71+
if (!($suffix)) {
72+
Write-Output "build: Creating release for version $versionPrefix"
73+
74+
iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)"
75+
}
76+
}
77+
} finally {
5578
Pop-Location
5679
}
57-
58-
Pop-Location

Directory.Build.props

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
<Project>
2-
2+
<!-- Properties in this file are expected to be identical for all Serilog organization projects. If
3+
a property value is project-specific, please record it in the CSPROJ file instead. -->
4+
<Import Project="$(MSBuildThisFileDirectory)Directory.Version.props" />
35
<PropertyGroup>
46
<LangVersion>latest</LangVersion>
57
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
6-
<SignAssembly>true</SignAssembly>
8+
<!-- The condition is required to support BenchmarkDotNet -->
9+
<SignAssembly Condition="Exists('$(MSBuildThisFileDirectory)assets/Serilog.snk')">true</SignAssembly>
710
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)assets/Serilog.snk</AssemblyOriginatorKeyFile>
8-
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
11+
<CheckEolTargetFramework>false</CheckEolTargetFramework>
912
<Nullable>enable</Nullable>
13+
<ImplicitUsings>enable</ImplicitUsings>
14+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
15+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
16+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
17+
<IncludeSymbols>true</IncludeSymbols>
18+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1019
</PropertyGroup>
11-
20+
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
21+
<Reference Include="System" />
22+
<Reference Include="System.Core" />
23+
<Reference Include="Microsoft.CSharp" />
24+
</ItemGroup>
1225
</Project>

Directory.Build.targets

Lines changed: 0 additions & 3 deletions
This file was deleted.

Directory.Version.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<PropertyGroup>
3+
<!-- This must match the major and minor components of the referenced Microsoft.Extensions.Logging package. -->
4+
<VersionPrefix>9.0.0</VersionPrefix>
5+
</PropertyGroup>
6+
</Project>

Setup.ps1

Lines changed: 0 additions & 9 deletions
This file was deleted.

appveyor.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

build.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

global.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"sdk": {
3-
"version": "8.0.100"
3+
"version": "9.0.100",
4+
"allowPrerelease": false,
5+
"rollForward": "latestFeature"
46
}
57
}

samples/Sample/Program.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,16 @@
33
using Serilog;
44
using Serilog.Extensions.Logging;
55

6-
// Creating a `LoggerProviderCollection` lets Serilog optionally write
7-
// events through other dynamically-added MEL ILoggerProviders.
8-
var providers = new LoggerProviderCollection();
9-
106
Log.Logger = new LoggerConfiguration()
11-
.MinimumLevel.Debug()
127
.WriteTo.Console()
13-
.WriteTo.Providers(providers)
148
.CreateLogger();
159

1610
var services = new ServiceCollection();
1711

18-
services.AddSingleton(providers);
19-
services.AddSingleton<ILoggerFactory>(sc =>
20-
{
21-
var providerCollection = sc.GetService<LoggerProviderCollection>();
22-
var factory = new SerilogLoggerFactory(null, true, providerCollection);
23-
24-
foreach (var provider in sc.GetServices<ILoggerProvider>())
25-
factory.AddProvider(provider);
26-
27-
return factory;
28-
});
29-
30-
services.AddLogging(l => l.AddConsole());
12+
services.AddLogging();
13+
services.AddSingleton<ILoggerFactory>(new SerilogLoggerFactory());
3114

32-
var serviceProvider = services.BuildServiceProvider();
15+
using var serviceProvider = services.BuildServiceProvider();
3316
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
3417

3518
var startTime = DateTimeOffset.UtcNow;
@@ -65,4 +48,3 @@
6548
logger.LogInformation("{Result,-10:l}{StartTime,15:l}{EndTime,15:l}{Duration,15:l}", "------", "----- ----", "--- ----", "------------");
6649
logger.LogInformation("{Result,-10:l}{StartTime,15:mm:s tt}{EndTime,15:mm:s tt}{Duration,15}", "SUCCESS", startTime, endTime, (endTime - startTime).TotalMilliseconds);
6750

68-
serviceProvider.Dispose();

samples/Sample/Properties/launchSettings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

samples/Sample/Sample.csproj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<AssemblyName>Sample</AssemblyName>
4+
<TargetFramework>net9.0</TargetFramework>
65
<OutputType>Exe</OutputType>
7-
<ImplicitUsings>enable</ImplicitUsings>
86
</PropertyGroup>
97

108
<ItemGroup>
119
<ProjectReference Include="..\..\src\Serilog.Extensions.Logging\Serilog.Extensions.Logging.csproj" />
1210
</ItemGroup>
1311

1412
<ItemGroup>
15-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
16-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
17-
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
13+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
14+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
15+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
1816
</ItemGroup>
1917

2018
</Project>

samples/SampleWithExternalScope/Program.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
// Add an ActivityListener (required, otherwise Activities don't actually get created if nothing is listening to them)
3131
ActivitySource.AddActivityListener(new ActivityListener
3232
{
33-
ShouldListenTo = source => true,
34-
Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllDataAndRecorded
33+
ShouldListenTo = _ => true,
34+
Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllDataAndRecorded
3535
});
3636

3737
// Run our test
3838
var activitySource = new ActivitySource("SomeActivitySource");
3939

40-
var serviceProvider = services.BuildServiceProvider();
40+
using var serviceProvider = services.BuildServiceProvider();
4141
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
4242

4343
using var activity = activitySource.StartActivity();
@@ -53,4 +53,3 @@
5353

5454
logger.LogInformation("Hello world!");
5555

56-
serviceProvider.Dispose();

samples/SampleWithExternalScope/SampleWithExternalScope.csproj

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<OutputType>Exe</OutputType>
8-
<Nullable>enable</Nullable>
5+
<TargetFramework>net9.0</TargetFramework>
96
</PropertyGroup>
107

118
<ItemGroup>
129
<ProjectReference Include="..\..\src\Serilog.Extensions.Logging\Serilog.Extensions.Logging.csproj" />
1310
</ItemGroup>
1411

1512
<ItemGroup>
16-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
17-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
18-
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
13+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
14+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
15+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
1916
</ItemGroup>
2017

2118
</Project>

0 commit comments

Comments
 (0)