Skip to content

Commit 4e3bb55

Browse files
authored
Merge pull request #388 from nblumhardt/dotnet-9
Update to .NET 9; Actions build
2 parents d47eefb + 613941a commit 4e3bb55

15 files changed

+156
-102
lines changed

.github/workflows/ci.yml

+41
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

+2
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,5 @@ __pycache__/
289289

290290
samples/Sample/logs/
291291

292+
.DS_Store
293+

Build.ps1

+58-35
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
916

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

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"]
20+
Write-Output "build: Package version prefix is $versionPrefix"
1521

16-
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 ""]
1727

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

21-
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" }
2233

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
27-
}
34+
foreach ($src in Get-ChildItem src/*) {
35+
Push-Location $src
2836

29-
if($LASTEXITCODE -ne 0) { exit 1 }
37+
Write-Output "build: Packaging project in $src"
3038

31-
Pop-Location
32-
}
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" }
3345

34-
foreach ($test in ls test/*.PerformanceTests) {
35-
Push-Location $test
46+
Pop-Location
47+
}
3648

37-
echo "build: Building performance test project in $test"
49+
foreach ($test in Get-ChildItem test/*.Tests) {
50+
Push-Location $test
3851

39-
& dotnet build -c Release
40-
if($LASTEXITCODE -ne 0) { exit 2 }
52+
Write-Output "build: Testing project in $test"
4153

42-
Pop-Location
43-
}
54+
& dotnet test -c Release --no-build --no-restore
55+
if($LASTEXITCODE -ne 0) { throw "Testing failed" }
56+
57+
Pop-Location
58+
}
4459

45-
foreach ($test in ls test/*.Tests) {
46-
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).
4763

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

50-
& dotnet test -c Release
51-
if($LASTEXITCODE -ne 0) { exit 3 }
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+
}
5270

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 {
5378
Pop-Location
5479
}
55-
56-
Pop-Location

Directory.Build.props

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
<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" />
25
<PropertyGroup>
36
<LangVersion>latest</LangVersion>
47
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
5-
<SignAssembly>true</SignAssembly>
6-
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
7-
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
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>
811
<CheckEolTargetFramework>false</CheckEolTargetFramework>
912
<Nullable>enable</Nullable>
1013
<ImplicitUsings>enable</ImplicitUsings>
14+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
15+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
16+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
17+
<IncludeSymbols>true</IncludeSymbols>
18+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1119
</PropertyGroup>
20+
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
21+
<Reference Include="System" />
22+
<Reference Include="System.Core" />
23+
<Reference Include="Microsoft.CSharp" />
24+
</ItemGroup>
1225
</Project>

Directory.Version.props

+6
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 *.Extensions.* packages (and highest supported .NET TFM). -->
4+
<VersionPrefix>9.0.0</VersionPrefix>
5+
</PropertyGroup>
6+
</Project>

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Serilog.AspNetCore [![Build status](https://ci.appveyor.com/api/projects/status/4rscdto23ik6vm2r/branch/dev?svg=true)](https://ci.appveyor.com/project/serilog/serilog-aspnetcore/branch/dev) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.AspNetCore.svg?style=flat)](https://www.nuget.org/packages/Serilog.AspNetCore/) [![NuGet Prerelease Version](http://img.shields.io/nuget/vpre/Serilog.AspNetCore.svg?style=flat)](https://www.nuget.org/packages/Serilog.AspNetCore/)
1+
# Serilog.AspNetCore&nbsp;[![Build status](https://github.com/serilog/serilog-aspnetcore/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/serilog/serilog-aspnetcore/actions)&nbsp;[![NuGet Version](http://img.shields.io/nuget/v/Serilog.AspNetCore.svg?style=flat)](https://www.nuget.org/packages/Serilog.AspNetCore/)
22

33
Serilog logging for ASP.NET Core. This package routes ASP.NET Core log messages through Serilog, so you can get information about ASP.NET's internal operations written to the same Serilog sinks as your application events.
44

Setup.ps1

-11
This file was deleted.

appveyor.yml

-24
This file was deleted.

global.json

+1-1
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
}

samples/Sample/Sample.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
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.AspNetCore\Serilog.AspNetCore.csproj" />
910
</ItemGroup>
1011

1112
<ItemGroup>
12-
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
13+
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
1314
</ItemGroup>
1415

1516
</Project>

serilog-aspnetcore.sln

+11-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ 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
19-
Setup.ps1 = Setup.ps1
16+
Build.ps1 = Build.ps1
17+
global.json = global.json
18+
Directory.Version.props = Directory.Version.props
2019
Directory.Build.props = Directory.Build.props
2120
EndProjectSection
2221
EndProject
@@ -26,6 +25,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.AspNetCore.Tests",
2625
EndProject
2726
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "samples\Sample\Sample.csproj", "{4FA0FE41-973E-4555-AB4A-0F400DBA9DD3}"
2827
EndProject
28+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{B867CAF4-D737-4230-AD2F-8093223A949A}"
29+
EndProject
30+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{5944D1E2-BC3C-4A95-B4E2-9DDE5B0684AC}"
31+
ProjectSection(SolutionItems) = preProject
32+
.github\workflows\ci.yml = .github\workflows\ci.yml
33+
EndProjectSection
34+
EndProject
2935
Global
3036
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3137
Debug|Any CPU = Debug|Any CPU
@@ -52,6 +58,7 @@ Global
5258
{0549D23F-986B-4FB2-BACE-16FD7A7BC9EF} = {A1893BD1-333D-4DFE-A0F0-DDBB2FE526E0}
5359
{AD51759B-CD58-473F-9620-0B0E56A123A1} = {E30F638E-BBBE-4AD1-93CE-48CC69CFEFE1}
5460
{4FA0FE41-973E-4555-AB4A-0F400DBA9DD3} = {F2407211-6043-439C-8E06-3641634332E7}
61+
{5944D1E2-BC3C-4A95-B4E2-9DDE5B0684AC} = {B867CAF4-D737-4230-AD2F-8093223A949A}
5562
EndGlobalSection
5663
GlobalSection(ExtensibilityGlobals) = postSolution
5764
SolutionGuid = {811E61C5-3871-4633-AFAE-B35B619C8A10}

src/Serilog.AspNetCore/AspNetCore/RequestLoggingMiddleware.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool LogCompletion(HttpContext httpContext, DiagnosticContextCollector collector
8888
collectedProperties = NoProperties;
8989

9090
// Last-in (correctly) wins...
91-
var properties = collectedProperties.Concat(_getMessageTemplateProperties(httpContext, GetPath(httpContext, _includeQueryInRequestPath), elapsedMs, statusCode));
91+
var properties = (collectedProperties ?? []).Concat(_getMessageTemplateProperties(httpContext, GetPath(httpContext, _includeQueryInRequestPath), elapsedMs, statusCode));
9292

9393
var (traceId, spanId) = Activity.Current is { } activity ?
9494
(activity.TraceId, activity.SpanId) :

src/Serilog.AspNetCore/Serilog.AspNetCore.csproj

+10-15
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22

33
<PropertyGroup>
44
<Description>Serilog support for ASP.NET Core logging</Description>
5-
<!-- This must match the major and minor components of the referenced *.Extensions.* packages (and highest supported .NET TFM). -->
6-
<VersionPrefix>8.0.4</VersionPrefix>
75
<Authors>Microsoft;Serilog Contributors</Authors>
8-
<TargetFrameworks>net462;netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
9-
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6+
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net8.0;net9.0</TargetFrameworks>
107
<PackageTags>serilog;aspnet;aspnetcore</PackageTags>
118
<PackageIcon>icon.png</PackageIcon>
129
<PackageProjectUrl>https://github.com/serilog/serilog-aspnetcore</PackageProjectUrl>
1310
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1411
<RepositoryUrl>https://github.com/serilog/serilog-aspnetcore</RepositoryUrl>
15-
<RepositoryType>git</RepositoryType>
1612
<RootNamespace>Serilog</RootNamespace>
1713
<PackageReadmeFile>README.md</PackageReadmeFile>
1814
</PropertyGroup>
@@ -24,26 +20,25 @@
2420
</ItemGroup>
2521

2622
<ItemGroup>
27-
<PackageReference Include="Serilog" Version="3.1.1" />
28-
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
29-
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
30-
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
31-
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
23+
<PackageReference Include="Serilog" Version="4.2.0-*" />
24+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
25+
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
26+
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
27+
<PackageReference Include="Serilog.Formatting.Compact" Version="3.0.0" />
3228
</ItemGroup>
3329

3430
<ItemGroup>
3531
<!-- The versions of all references in this group must match the major and minor components of the package version prefix. -->
36-
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
37-
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
38-
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
32+
<PackageReference Include="Serilog.Extensions.Hosting" Version="9.0.0-*" />
33+
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0-*" />
3934
</ItemGroup>
4035

41-
<ItemGroup Condition=" '$(TargetFramework)' != 'net462' and '$(TargetFramework)' != 'netstandard2.0' ">
36+
<ItemGroup Condition=" '$(TargetFramework)' != 'net462' and '$(TargetFramework)' != 'netstandard2.0' and '$(TargetFramework)' != 'netstandard2.1' ">
4237
<!-- I.e. all modern/supported non-Framework .NET SKUs -->
4338
<FrameworkReference Include="Microsoft.AspNetCore.App" />
4439
</ItemGroup>
4540

46-
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0' ">
41+
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' ">
4742
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
4843
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
4944
</ItemGroup>
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<Project Sdk="Microsoft.NET.Sdk">
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.AspNetCore\Serilog.AspNetCore.csproj" />
910
</ItemGroup>
1011

1112
<ItemGroup>
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
13-
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" PrivateAssets="all" />
14-
<PackageReference Include="xunit" Version="2.6.1" />
15-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="all" />
15+
<PackageReference Include="xunit" Version="2.9.2" />
16+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
1617
</ItemGroup>
1718

1819
</Project>

0 commit comments

Comments
 (0)