Skip to content

Commit 689f2d4

Browse files
authored
Merge pull request #97 from serilog/dev
9.0.0 Release
2 parents 11a23e3 + 1a13094 commit 689f2d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3053
-2596
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,6 @@ __pycache__/
286286
*.odx.cs
287287
*.xsd.cs
288288
/samples/WebApplicationSample/logs/
289+
290+
.DS_Store
291+

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>

README.md

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
# Serilog.Extensions.Hosting [![Build status](https://ci.appveyor.com/api/projects/status/ue4s7htjwj88fulh?svg=true)](https://ci.appveyor.com/project/serilog/serilog-extensions-hosting) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Extensions.Hosting.svg?style=flat)](https://www.nuget.org/packages/Serilog.Extensions.Hosting/)
1+
# Serilog.Extensions.Hosting&nbsp;[![Build status](https://github.com/serilog/serilog-extensions-hosting/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/serilog/serilog-extensions-hosting/actions)&nbsp;[![NuGet Version](http://img.shields.io/nuget/v/Serilog.Extensions.Hosting.svg?style=flat)](https://www.nuget.org/packages/Serilog.Extensions.Hosting/)
22

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

5-
**ASP.NET Core** applications should consider [using _Serilog.AspNetCore_ instead](https://github.com/serilog/serilog-aspnetcore), which bundles this package and includes other ASP.NET Core-specific features.
5+
**Versioning:** This package tracks the versioning and target framework support of its
6+
[_Microsoft.Extensions.Hosting_](https://nuget.org/packages/Microsoft.Extensions.Hosting) dependency. Most users should choose the version of _Serilog.Extensions.Hosting_ that matches
7+
their application's target framework. I.e. if you're targeting .NET 7.x, choose a 7.x version of _Serilog.Extensions.Hosting_. If
8+
you're targeting .NET 8.x, choose an 8.x _Serilog.Extensions.Hosting_ version, and so on.
69

710
### Instructions
811

@@ -13,46 +16,37 @@ dotnet add package Serilog.Extensions.Hosting
1316
dotnet add package Serilog.Sinks.Console
1417
```
1518

16-
**Next**, in your application's _Program.cs_ file, configure Serilog first. A `try`/`catch` block will ensure any configuration issues are appropriately logged:
19+
**Next**, in your application's _Program.cs_ file, configure Serilog first. A `try`/`catch` block will ensure any configuration issues are appropriately logged. Call `AddSerilog()` on the host application builder:
1720

1821
```csharp
19-
public class Program
22+
using Serilog;
23+
24+
Log.Logger = new LoggerConfiguration()
25+
.Enrich.FromLogContext()
26+
.WriteTo.Console()
27+
.CreateLogger();
28+
29+
try
2030
{
21-
public static int Main(string[] args)
22-
{
23-
Log.Logger = new LoggerConfiguration()
24-
.MinimumLevel.Debug()
25-
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
26-
.Enrich.FromLogContext()
27-
.WriteTo.Console()
28-
.CreateLogger();
29-
30-
try
31-
{
32-
Log.Information("Starting host");
33-
BuildHost(args).Run();
34-
return 0;
35-
}
36-
catch (Exception ex)
37-
{
38-
Log.Fatal(ex, "Host terminated unexpectedly");
39-
return 1;
40-
}
41-
finally
42-
{
43-
Log.CloseAndFlush();
44-
}
45-
}
46-
```
31+
Log.Information("Starting host");
4732

48-
**Then**, add `UseSerilog()` to the host builder in `BuildHost()`.
33+
var builder = Host.CreateApplicationBuilder(args);
34+
builder.Services.AddHostedService<PrintTimeService>();
35+
builder.Services.AddSerilog();
4936

50-
```csharp
51-
public static IHost BuildHost(string[] args) =>
52-
new HostBuilder()
53-
.ConfigureServices(services => services.AddSingleton<IHostedService, PrintTimeService>())
54-
.UseSerilog() // <- Add this line
55-
.Build();
37+
var app = builder.Build();
38+
39+
await app.RunAsync();
40+
return 0;
41+
}
42+
catch (Exception ex)
43+
{
44+
Log.Fatal(ex, "Host terminated unexpectedly");
45+
return 1;
46+
}
47+
finally
48+
{
49+
await Log.CloseAndFlushAsync();
5650
}
5751
```
5852

@@ -71,24 +65,18 @@ A more complete example, showing _appsettings.json_ configuration, can be found
7165

7266
With _Serilog.Extensions.Hosting_ installed and configured, you can write log messages directly through Serilog or any `ILogger` interface injected by .NET. All loggers will use the same underlying implementation, levels, and destinations.
7367

74-
**Tip:** change the minimum level for `Microsoft` to `Warning`
75-
7668
### Inline initialization
7769

7870
You can alternatively configure Serilog using a delegate as shown below:
7971

8072
```csharp
8173
// dotnet add package Serilog.Settings.Configuration
82-
.UseSerilog((hostingContext, services, loggerConfiguration) => loggerConfiguration
83-
.ReadFrom.Configuration(hostingContext.Configuration)
84-
.Enrich.FromLogContext()
85-
.WriteTo.Console())
74+
builder.Services.AddSerilog((services, loggerConfiguration) => loggerConfiguration
75+
.ReadFrom.Configuration(builder.Configuration)
76+
.Enrich.FromLogContext()
77+
.WriteTo.Console())
8678
```
8779

88-
This has the advantage of making the `hostingContext`'s `Configuration` object available for configuration of the logger, but at the expense of ignoring `Exception`s raised earlier in program startup.
80+
This has the advantage of making `builder`'s `Configuration` object available for configuration of the logger, but at the expense of ignoring `Exception`s raised earlier in program startup.
8981

9082
If this method is used, `Log.Logger` is assigned implicitly, and closed when the app is shut down.
91-
92-
### Versioning
93-
94-
This package tracks the versioning and target framework support of its [_Microsoft.Extensions.Hosting_](https://nuget.org/packages/Microsoft.Extensions.Hosting) dependency.

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
}

0 commit comments

Comments
 (0)