Skip to content

Commit 796456d

Browse files
committed
Update to .NET 9 SDK and Microsoft.Extensions.Hosting 9.0.0; Actions build; extend CreateBoostrapLogger() support to all TFMs
1 parent 4ec0cc2 commit 796456d

29 files changed

+1265
-732
lines changed

.DS_Store

6 KB
Binary file not shown.

.github/.DS_Store

6 KB
Binary file not shown.

.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

Build.ps1

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,79 @@
1-
echo "build: Build started"
1+
Write-Output "build: Tool versions follow"
2+
3+
dotnet --version
4+
dotnet --list-sdks
5+
6+
Write-Output "build: Build started"
27

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

5-
if(Test-Path .\artifacts) {
6-
echo "build: Cleaning .\artifacts"
7-
Remove-Item .\artifacts -Force -Recurse
8-
}
15+
& dotnet restore --no-cache
16+
17+
$dbp = [Xml] (Get-Content .\Directory.Version.props)
18+
$versionPrefix = $dbp.Project.PropertyGroup.VersionPrefix
19+
20+
Write-Output "build: Package version prefix is $versionPrefix"
21+
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 ""]
927

10-
& dotnet restore --no-cache
28+
Write-Output "build: Package version suffix is $suffix"
29+
Write-Output "build: Build version suffix is $buildSuffix"
1130

12-
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
13-
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
14-
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"]
31+
& dotnet build -c Release --version-suffix=$buildSuffix /p:ContinuousIntegrationBuild=true
32+
if($LASTEXITCODE -ne 0) { throw "Build failed" }
1533

16-
echo "build: Version suffix is $suffix"
34+
foreach ($src in Get-ChildItem src/*) {
35+
Push-Location $src
1736

18-
foreach ($src in ls src/*) {
19-
Push-Location $src
37+
Write-Output "build: Packaging project in $src"
2038

21-
echo "build: Packaging project in $src"
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" }
2245

23-
if($suffix) {
24-
& dotnet pack -c Release --include-source -o ..\..\artifacts --version-suffix=$suffix
25-
} else {
26-
& dotnet pack -c Release --include-source -o ..\..\artifacts
46+
Pop-Location
2747
}
28-
29-
if($LASTEXITCODE -ne 0) { exit 1 }
3048

31-
Pop-Location
32-
}
49+
foreach ($test in Get-ChildItem test/*.Tests) {
50+
Push-Location $test
3351

34-
foreach ($test in ls test/*.PerformanceTests) {
35-
Push-Location $test
52+
Write-Output "build: Testing project in $test"
3653

37-
echo "build: Building performance test project in $test"
54+
& dotnet test -c Release --no-build --no-restore
55+
if($LASTEXITCODE -ne 0) { throw "Testing failed" }
3856

39-
& dotnet build -c Release
40-
if($LASTEXITCODE -ne 0) { exit 2 }
57+
Pop-Location
58+
}
4159

42-
Pop-Location
43-
}
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).
4463

45-
foreach ($test in ls test/*.Tests) {
46-
Push-Location $test
64+
Write-Output "build: Publishing NuGet packages"
4765

48-
echo "build: Testing project in $test"
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+
}
4970

50-
& dotnet test -c Release
51-
if($LASTEXITCODE -ne 0) { exit 3 }
71+
if (!($suffix)) {
72+
Write-Output "build: Creating release for version $versionPrefix"
5273

74+
iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)"
75+
}
76+
}
77+
} finally {
5378
Pop-Location
5479
}
55-
56-
Pop-Location

Directory.Build.props

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project>
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" />
5+
<PropertyGroup>
6+
<LangVersion>latest</LangVersion>
7+
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
8+
<!-- The condition is required to support BenchmarkDotNet -->
9+
<SignAssembly Condition="Exists('$(MSBuildThisFileDirectory)assets/Serilog.snk')">true</SignAssembly>
10+
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)assets/Serilog.snk</AssemblyOriginatorKeyFile>
11+
<CheckEolTargetFramework>false</CheckEolTargetFramework>
12+
<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>
19+
</PropertyGroup>
20+
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
21+
<Reference Include="System" />
22+
<Reference Include="System.Core" />
23+
<Reference Include="Microsoft.CSharp" />
24+
</ItemGroup>
25+
</Project>

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.Hosting package. -->
4+
<VersionPrefix>9.0.0</VersionPrefix>
5+
</PropertyGroup>
6+
</Project>

appveyor.yml

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

build.sh

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

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"sdk": {
3+
"version": "9.0.100",
34
"allowPrerelease": false,
4-
"version": "8.0.100",
55
"rollForward": "latestFeature"
66
}
77
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk.Worker">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<GenerateDocumentationFile>false</GenerateDocumentationFile>
56
</PropertyGroup>
67

78
<ItemGroup>
89
<ProjectReference Include="..\..\src\Serilog.Extensions.Hosting\Serilog.Extensions.Hosting.csproj" />
910
</ItemGroup>
1011

1112
<ItemGroup>
12-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
13-
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
14-
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
13+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
14+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
15+
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0-*" />
1516
</ItemGroup>
1617

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

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<GenerateDocumentationFile>false</GenerateDocumentationFile>
56
</PropertyGroup>
67

78
<ItemGroup>
89
<ProjectReference Include="..\..\src\Serilog.Extensions.Hosting\Serilog.Extensions.Hosting.csproj" />
910
</ItemGroup>
1011

1112
<ItemGroup>
12-
<PackageReference Include="serilog.settings.configuration" Version="8.0.0" />
13-
<PackageReference Include="serilog.sinks.console" Version="5.0.0" />
14-
<PackageReference Include="serilog.sinks.file" Version="5.0.0" />
13+
<PackageReference Include="serilog.settings.configuration" Version="9.0.0-*" />
14+
<PackageReference Include="serilog.sinks.console" Version="6.0.0" />
15+
<PackageReference Include="serilog.sinks.file" Version="6.0.0" />
1516
</ItemGroup>
1617

1718
</Project>

serilog-extensions-hosting.sln

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{F240
1111
EndProject
1212
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{9C21B9DF-AEDD-4AA6-BEA4-912DEF3E5B8E}"
1313
ProjectSection(SolutionItems) = preProject
14-
appveyor.yml = appveyor.yml
15-
Build.ps1 = Build.ps1
16-
global.json = global.json
1714
README.md = README.md
1815
assets\Serilog.snk = assets\Serilog.snk
16+
Build.ps1 = Build.ps1
17+
global.json = global.json
18+
Directory.Version.props = Directory.Version.props
19+
Directory.Build.props = Directory.Build.props
1920
EndProjectSection
2021
EndProject
2122
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Extensions.Hosting", "src\Serilog.Extensions.Hosting\Serilog.Extensions.Hosting.csproj", "{0549D23F-986B-4FB2-BACE-16FD7A7BC9EF}"
@@ -26,6 +27,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleServiceSample", "samp
2627
EndProject
2728
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplicationSample", "samples\WebApplicationSample\WebApplicationSample.csproj", "{1ACDCA67-F404-45AB-9348-98E55E03CB8C}"
2829
EndProject
30+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{5C68E1CE-D650-4500-B32C-21EDD0AAA0A7}"
31+
EndProject
32+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{10168223-6AEF-4B08-B6FD-50C6FD3B6E84}"
33+
ProjectSection(SolutionItems) = preProject
34+
.github\workflows\ci.yml = .github\workflows\ci.yml
35+
EndProjectSection
36+
EndProject
2937
Global
3038
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3139
Debug|Any CPU = Debug|Any CPU
@@ -57,6 +65,7 @@ Global
5765
{AD51759B-CD58-473F-9620-0B0E56A123A1} = {E30F638E-BBBE-4AD1-93CE-48CC69CFEFE1}
5866
{E5A82756-4619-4E6B-8B26-6D83E00E99F0} = {F2407211-6043-439C-8E06-3641634332E7}
5967
{1ACDCA67-F404-45AB-9348-98E55E03CB8C} = {F2407211-6043-439C-8E06-3641634332E7}
68+
{10168223-6AEF-4B08-B6FD-50C6FD3B6E84} = {5C68E1CE-D650-4500-B32C-21EDD0AAA0A7}
6069
EndGlobalSection
6170
GlobalSection(ExtensibilityGlobals) = postSolution
6271
SolutionGuid = {811E61C5-3871-4633-AFAE-B35B619C8A10}

src/Serilog.Extensions.Hosting/Extensions/Hosting/AmbientDiagnosticContextCollector.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,17 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
using System;
16-
using System.Threading;
17-
1815
namespace Serilog.Extensions.Hosting;
1916

2017
class AmbientDiagnosticContextCollector : IDisposable
2118
{
22-
static readonly AsyncLocal<AmbientDiagnosticContextCollector> AmbientCollector =
23-
new AsyncLocal<AmbientDiagnosticContextCollector>();
19+
static readonly AsyncLocal<AmbientDiagnosticContextCollector?> AmbientCollector = new();
2420

2521
// The indirection here ensures that completing collection cleans up the collector in all
2622
// execution contexts. Via @benaadams' addition to `HttpContextAccessor` :-)
27-
DiagnosticContextCollector _collector;
23+
DiagnosticContextCollector? _collector;
2824

29-
public static DiagnosticContextCollector Current => AmbientCollector.Value?._collector;
25+
public static DiagnosticContextCollector? Current => AmbientCollector.Value?._collector;
3026

3127
public static DiagnosticContextCollector Begin()
3228
{

0 commit comments

Comments
 (0)