diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..acd3bc6
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,41 @@
+# If this file is renamed, the incrementing run attempt number will be reset.
+
+name: CI
+
+on:
+ push:
+ branches: [ "dev", "main" ]
+ pull_request:
+ branches: [ "dev", "main" ]
+
+env:
+ CI_BUILD_NUMBER_BASE: ${{ github.run_number }}
+ CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
+
+jobs:
+ build:
+
+ # The build must run on Windows so that .NET Framework targets can be built and tested.
+ runs-on: windows-latest
+
+ permissions:
+ contents: write
+
+ steps:
+ - uses: actions/checkout@v4
+ - name: Setup
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: 9.0.x
+ - name: Compute build number
+ shell: bash
+ run: |
+ echo "CI_BUILD_NUMBER=$(($CI_BUILD_NUMBER_BASE+2300))" >> $GITHUB_ENV
+ - name: Build and Publish
+ env:
+ DOTNET_CLI_TELEMETRY_OPTOUT: true
+ NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ shell: pwsh
+ run: |
+ ./Build.ps1
diff --git a/.gitignore b/.gitignore
index 7b17e06..febeee0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -200,4 +200,7 @@ project.lock.json
# JetBrains Rider
.idea
-.vscode
\ No newline at end of file
+.vscode
+
+.DS_Store
+
diff --git a/Build.ps1 b/Build.ps1
index 431f4e2..e798284 100644
--- a/Build.ps1
+++ b/Build.ps1
@@ -1,58 +1,79 @@
-echo "build: Build started"
+Write-Output "build: Tool versions follow"
-$env:Path = "$pwd/.dotnetcli;$env:Path"
+dotnet --version
+dotnet --list-sdks
+
+Write-Output "build: Build started"
Push-Location $PSScriptRoot
+try {
+ if(Test-Path .\artifacts) {
+ Write-Output "build: Cleaning ./artifacts"
+ Remove-Item ./artifacts -Force -Recurse
+ }
-if(Test-Path .\artifacts) {
- echo "build: Cleaning .\artifacts"
- Remove-Item .\artifacts -Force -Recurse
-}
+ & dotnet restore --no-cache
-& dotnet restore --no-cache
+ $dbp = [Xml] (Get-Content .\Directory.Version.props)
+ $versionPrefix = $dbp.Project.PropertyGroup.VersionPrefix
-$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
-$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
-$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"]
+ Write-Output "build: Package version prefix is $versionPrefix"
-echo "build: Version suffix is $suffix"
+ $branch = @{ $true = $env:CI_TARGET_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:CI_TARGET_BRANCH];
+ $revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:CI_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:CI_BUILD_NUMBER];
+ $suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '([^a-zA-Z0-9\-]*)', '')-$revision"}[$branch -eq "main" -and $revision -ne "local"]
+ $commitHash = $(git rev-parse --short HEAD)
+ $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
-foreach ($src in ls src/*) {
- Push-Location $src
+ Write-Output "build: Package version suffix is $suffix"
+ Write-Output "build: Build version suffix is $buildSuffix"
- echo "build: Packaging project in $src"
+ & dotnet build -c Release --version-suffix=$buildSuffix /p:ContinuousIntegrationBuild=true
+ if($LASTEXITCODE -ne 0) { throw "Build failed" }
- if($suffix) {
- & dotnet pack -c Release --include-source -o ..\..\artifacts --version-suffix=$suffix
- } else {
- & dotnet pack -c Release --include-source -o ..\..\artifacts
- }
+ foreach ($src in Get-ChildItem src/*) {
+ Push-Location $src
- if($LASTEXITCODE -ne 0) { throw "build failed" }
+ Write-Output "build: Packaging project in $src"
- Pop-Location
-}
+ if ($suffix) {
+ & dotnet pack -c Release --no-build --no-restore -o ../../artifacts --version-suffix=$suffix
+ } else {
+ & dotnet pack -c Release --no-build --no-restore -o ../../artifacts
+ }
+ if($LASTEXITCODE -ne 0) { throw "Packaging failed" }
+
+ Pop-Location
+ }
-foreach ($test in ls test/*.PerformanceTests) {
- Push-Location $test
+ foreach ($test in Get-ChildItem test/*.Tests) {
+ Push-Location $test
- echo "build: Building performance test project in $test"
+ Write-Output "build: Testing project in $test"
- & dotnet build -c Release
- if($LASTEXITCODE -ne 0) { throw "test failed" }
+ & dotnet test -c Release --no-build --no-restore
+ if($LASTEXITCODE -ne 0) { throw "Testing failed" }
- Pop-Location
-}
+ Pop-Location
+ }
-foreach ($test in ls test/*.Tests) {
- Push-Location $test
+ if ($env:NUGET_API_KEY) {
+ # GitHub Actions will only supply this to branch builds and not PRs. We publish
+ # builds from any branch this action targets (i.e. main and dev).
- echo "build: Testing project in $test"
+ Write-Output "build: Publishing NuGet packages"
- & dotnet test -c Release
- if($LASTEXITCODE -ne 0) { throw "test failed" }
+ foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) {
+ & dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg"
+ if($LASTEXITCODE -ne 0) { throw "Publishing failed" }
+ }
+ if (!($suffix)) {
+ Write-Output "build: Creating release for version $versionPrefix"
+
+ iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)"
+ }
+ }
+} finally {
Pop-Location
}
-
-Pop-Location
diff --git a/Directory.Build.props b/Directory.Build.props
index 2b620bc..c114992 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,12 +1,25 @@
-
+
+
latest
True
- true
+
+ true
$(MSBuildThisFileDirectory)assets/Serilog.snk
- true
+ false
enable
+ enable
+ true
+ true
+ true
+ true
+ snupkg
-
+
+
+
+
+
diff --git a/Directory.Build.targets b/Directory.Build.targets
deleted file mode 100644
index faf2349..0000000
--- a/Directory.Build.targets
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
diff --git a/Directory.Version.props b/Directory.Version.props
new file mode 100644
index 0000000..3077571
--- /dev/null
+++ b/Directory.Version.props
@@ -0,0 +1,6 @@
+
+
+
+ 9.0.0
+
+
diff --git a/Setup.ps1 b/Setup.ps1
deleted file mode 100644
index aa90b5b..0000000
--- a/Setup.ps1
+++ /dev/null
@@ -1,9 +0,0 @@
-$ErrorActionPreference = "Stop"
-
-$RequiredDotnetVersion = $(cat ./global.json | convertfrom-json).sdk.version
-
-New-Item -ItemType Directory -Force "./build/" | Out-Null
-
-Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile "./build/installcli.ps1"
-& ./build/installcli.ps1 -InstallDir "$pwd/.dotnetcli" -NoPath -Version $RequiredDotnetVersion
-if ($LASTEXITCODE) { throw ".NET install failed" }
diff --git a/appveyor.yml b/appveyor.yml
deleted file mode 100644
index b7e0f44..0000000
--- a/appveyor.yml
+++ /dev/null
@@ -1,26 +0,0 @@
-version: '{build}'
-skip_tags: true
-image: Visual Studio 2022
-install:
-- pwsh: ./Setup.ps1
-- pwsh: mkdir -Force ".\build\" | Out-Null
-build_script:
-- pwsh: ./Build.ps1
-test: off
-artifacts:
-- path: artifacts/Serilog.*.nupkg
-deploy:
-- provider: NuGet
- api_key:
- secure: H96ajkMxwIafhF2vrr+UAUS10bFcAL/1wc3iphidRiYi9WoTc2i8shTLtF+75ODb
- skip_symbols: true
- on:
- branch: /^(main|dev)$/
-- provider: GitHub
- auth_token:
- secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
- artifact: /Serilog.*\.nupkg/
- tag: v$(appveyor_build_version)
- on:
- branch: main
-
diff --git a/build.sh b/build.sh
deleted file mode 100644
index 6d1ff38..0000000
--- a/build.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-dotnet --info
-dotnet restore
-
-for path in src/**/*.csproj; do
- dotnet build -f netstandard2.0 -c Release ${path}
-
-done
-
-for path in test/*.Tests/*.csproj; do
- dotnet test -f netcoreapp2.0 -c Release ${path}
-done
\ No newline at end of file
diff --git a/global.json b/global.json
index 5ce8495..db8627a 100644
--- a/global.json
+++ b/global.json
@@ -1,5 +1,7 @@
{
"sdk": {
- "version": "8.0.100"
+ "version": "9.0.100",
+ "allowPrerelease": false,
+ "rollForward": "latestFeature"
}
}
diff --git a/samples/Sample/Program.cs b/samples/Sample/Program.cs
index d70b9aa..b369510 100644
--- a/samples/Sample/Program.cs
+++ b/samples/Sample/Program.cs
@@ -3,33 +3,16 @@
using Serilog;
using Serilog.Extensions.Logging;
-// Creating a `LoggerProviderCollection` lets Serilog optionally write
-// events through other dynamically-added MEL ILoggerProviders.
-var providers = new LoggerProviderCollection();
-
Log.Logger = new LoggerConfiguration()
- .MinimumLevel.Debug()
.WriteTo.Console()
- .WriteTo.Providers(providers)
.CreateLogger();
var services = new ServiceCollection();
-services.AddSingleton(providers);
-services.AddSingleton(sc =>
-{
- var providerCollection = sc.GetService();
- var factory = new SerilogLoggerFactory(null, true, providerCollection);
-
- foreach (var provider in sc.GetServices())
- factory.AddProvider(provider);
-
- return factory;
-});
-
-services.AddLogging(l => l.AddConsole());
+services.AddLogging();
+services.AddSingleton(new SerilogLoggerFactory());
-var serviceProvider = services.BuildServiceProvider();
+using var serviceProvider = services.BuildServiceProvider();
var logger = serviceProvider.GetRequiredService>();
var startTime = DateTimeOffset.UtcNow;
@@ -65,4 +48,3 @@
logger.LogInformation("{Result,-10:l}{StartTime,15:l}{EndTime,15:l}{Duration,15:l}", "------", "----- ----", "--- ----", "------------");
logger.LogInformation("{Result,-10:l}{StartTime,15:mm:s tt}{EndTime,15:mm:s tt}{Duration,15}", "SUCCESS", startTime, endTime, (endTime - startTime).TotalMilliseconds);
-serviceProvider.Dispose();
diff --git a/samples/Sample/Properties/launchSettings.json b/samples/Sample/Properties/launchSettings.json
deleted file mode 100644
index 43e0c99..0000000
--- a/samples/Sample/Properties/launchSettings.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "profiles": {}
-}
\ No newline at end of file
diff --git a/samples/Sample/Sample.csproj b/samples/Sample/Sample.csproj
index 951b742..793b13a 100644
--- a/samples/Sample/Sample.csproj
+++ b/samples/Sample/Sample.csproj
@@ -1,10 +1,8 @@
- net8.0
- Sample
+ net9.0
Exe
- enable
@@ -12,9 +10,9 @@
-
-
-
+
+
+
diff --git a/samples/SampleWithExternalScope/Program.cs b/samples/SampleWithExternalScope/Program.cs
index 3a1a018..2b0aad7 100644
--- a/samples/SampleWithExternalScope/Program.cs
+++ b/samples/SampleWithExternalScope/Program.cs
@@ -30,14 +30,14 @@
// Add an ActivityListener (required, otherwise Activities don't actually get created if nothing is listening to them)
ActivitySource.AddActivityListener(new ActivityListener
{
- ShouldListenTo = source => true,
- Sample = (ref ActivityCreationOptions options) => ActivitySamplingResult.AllDataAndRecorded
+ ShouldListenTo = _ => true,
+ Sample = (ref ActivityCreationOptions _) => ActivitySamplingResult.AllDataAndRecorded
});
// Run our test
var activitySource = new ActivitySource("SomeActivitySource");
-var serviceProvider = services.BuildServiceProvider();
+using var serviceProvider = services.BuildServiceProvider();
var logger = serviceProvider.GetRequiredService>();
using var activity = activitySource.StartActivity();
@@ -53,4 +53,3 @@
logger.LogInformation("Hello world!");
-serviceProvider.Dispose();
diff --git a/samples/SampleWithExternalScope/SampleWithExternalScope.csproj b/samples/SampleWithExternalScope/SampleWithExternalScope.csproj
index 045c31a..84cb0ac 100644
--- a/samples/SampleWithExternalScope/SampleWithExternalScope.csproj
+++ b/samples/SampleWithExternalScope/SampleWithExternalScope.csproj
@@ -2,10 +2,7 @@
Exe
- net8.0
- enable
- Exe
- enable
+ net9.0
@@ -13,9 +10,9 @@
-
-
-
+
+
+
diff --git a/samples/SampleWithMelProviders/Program.cs b/samples/SampleWithMelProviders/Program.cs
new file mode 100644
index 0000000..c8b88b1
--- /dev/null
+++ b/samples/SampleWithMelProviders/Program.cs
@@ -0,0 +1,69 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using Serilog;
+using Serilog.Extensions.Logging;
+
+// Creating a `LoggerProviderCollection` lets Serilog optionally write
+// events through other dynamically-added MEL ILoggerProviders.
+var providers = new LoggerProviderCollection();
+
+// The sample sets up Serilog's console sink here:
+Log.Logger = new LoggerConfiguration()
+ .MinimumLevel.Debug()
+ .WriteTo.Console()
+ .WriteTo.Providers(providers)
+ .CreateLogger();
+
+var services = new ServiceCollection();
+
+services.AddSingleton(providers);
+services.AddSingleton(sc =>
+{
+ var providerCollection = sc.GetService();
+ var factory = new SerilogLoggerFactory(null, true, providerCollection);
+
+ foreach (var provider in sc.GetServices())
+ factory.AddProvider(provider);
+
+ return factory;
+});
+
+// ..and MEL's console provider here:
+services.AddLogging(l => l.AddConsole());
+
+using var serviceProvider = services.BuildServiceProvider();
+var logger = serviceProvider.GetRequiredService>();
+
+var startTime = DateTimeOffset.UtcNow;
+logger.LogInformation(1, "Started at {StartTime} and 0x{Hello:X} is hex of 42", startTime, 42);
+
+try
+{
+ throw new Exception("Boom!");
+}
+catch (Exception ex)
+{
+ logger.LogCritical(ex, "Unexpected critical error starting application");
+ logger.Log(LogLevel.Critical, 0, "Unexpected critical error", ex, null!);
+ // This write should not log anything
+ logger.Log