Skip to content

Commit 798ec09

Browse files
committed
Update to .NET 9; Actions build; drop deprecated dependencies; clean up
1 parent 8761025 commit 798ec09

File tree

80 files changed

+493
-23843
lines changed

Some content is hidden

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

80 files changed

+493
-23843
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Bug report
3+
about: Report a bug and help us to improve Serilog
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
The Serilog maintainers want you to have a great experience using Serilog, and will happily track down and resolve bugs. We all have limited time, though, so please think through all of the factors that might be involved and include as much useful information as possible 😊.
11+
12+
ℹ If the problem is caused by a sink or other extension package, please track down the correct repository for that package and create the report there: this tracker is for the core **Serilog** package only.
13+
14+
**Description**
15+
What's going wrong?
16+
17+
**Reproduction**
18+
Please provide code samples showing how you're configuring and calling Serilog to produce the behavior.
19+
20+
**Expected behavior**
21+
A concise description of what you expected to happen.
22+
23+
**Relevant package, tooling and runtime versions**
24+
What Serilog version are you using, on what platform?
25+
26+
**Additional context**
27+
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
contact_links:
2+
- name: Ask for help
3+
url: https://github.com/serilog/serilog/wiki/Usage-help
4+
about: Ask the community for help on how to use Serilog
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an improvement to Serilog
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.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

+3
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,6 @@ paket-files/
250250
# JetBrains Rider
251251
.idea/
252252
*.sln.iml
253+
254+
.DS_Store
255+

Build.ps1

+61-32
Original file line numberDiff line numberDiff line change
@@ -1,50 +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"]
15-
$commitHash = $(git rev-parse --short HEAD)
16-
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
20+
Write-Output "build: Package version prefix is $versionPrefix"
1721

18-
echo "build: Package version suffix is $suffix"
19-
echo "build: Build version suffix is $buildSuffix"
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 ""]
2027

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

24-
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" }
2533

26-
& dotnet build -c Release --version-suffix=$buildSuffix
27-
if($LASTEXITCODE -ne 0) { exit 1 }
34+
foreach ($src in Get-ChildItem src/*) {
35+
Push-Location $src
2836

29-
if ($suffix) {
30-
& dotnet pack -c Release --include-symbols -o ..\..\artifacts --version-suffix=$suffix --no-build
31-
} else {
32-
& dotnet pack -c Release --include-symbols -o ..\..\artifacts --no-build
37+
Write-Output "build: Packaging project in $src"
38+
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
3347
}
34-
if($LASTEXITCODE -ne 0) { exit 1 }
3548

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

39-
foreach ($test in ls test/*.Tests) {
40-
Push-Location $test
52+
Write-Output "build: Testing project in $test"
4153

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

44-
& dotnet test -c Release
45-
if($LASTEXITCODE -ne 0) { exit 3 }
57+
Pop-Location
58+
}
59+
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).
63+
64+
Write-Output "build: Publishing NuGet packages"
65+
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+
}
4670

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 {
4778
Pop-Location
4879
}
49-
50-
Pop-Location

Directory.Build.props

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

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<PropertyGroup>
3+
<!-- This must track the version of the targeted Serilog.Extensions.Logging package. -->
4+
<VersionPrefix>9.0.0</VersionPrefix>
5+
</PropertyGroup>
6+
</Project>

README.md

+14-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Serilog.Extensions.Logging.File [![NuGet Pre Release](https://img.shields.io/nuget/vpre/Serilog.Extensions.Logging.File.svg)](https://nuget.org/packages/Serilog.Extensions.Logging.File) [![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog) [![Build status](https://ci.appveyor.com/api/projects/status/rdff6bp9oeqfxif7?svg=true)](https://ci.appveyor.com/project/serilog/serilog-extensions-logging-file)
1+
# Serilog.Extensions.Logging.File&nbsp;[![Build status](https://github.com/serilog/serilog-extensions-logging-file/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/serilog/serilog-extensions-logging-file/actions)&nbsp;[![NuGet Version](http://img.shields.io/nuget/v/Serilog.Extensions.Logging.File.svg?style=flat)](https://www.nuget.org/packages/Serilog.Extensions.Logging.File/)
22

33
This package makes it a one-liner - `loggingBuilder.AddFile()` - to configure top-quality file logging for ASP.NET Core apps.
44

@@ -11,40 +11,28 @@ This package makes it a one-liner - `loggingBuilder.AddFile()` - to configure to
1111

1212
You can get started quickly with this package, and later migrate to the full Serilog API if you need more sophisticated log file configuration.
1313

14+
### Versioning
15+
16+
This package tracks the version of ASP.NET Core that it targets. If you're using 9.x.x of ASP.NET Core, use 9.x.x of _Serilog.Extensions.Logging.File_, and so on.
17+
18+
> If the version you're using doesn't have a corresponding _Serilog.Extensions.Logging.File_ release, target v3.x of this package.
19+
1420
### Getting started
1521

1622
**1.** Add [the NuGet package](https://nuget.org/packages/serilog.extensions.logging.file) as a dependency of your project either with the package manager or directly to the CSPROJ file:
1723

1824
```xml
19-
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
25+
<PackageReference Include="Serilog.Extensions.Logging.File" Version="9.0.0" />
2026
```
2127

22-
**2.** In your `Program` class, configure logging on the host builder, and call `AddFile()` on the provided `loggingBuilder`:
28+
**2.** In your `Program` class, configure logging on the host builder, and call `AddFile()` on the provided `ILoggingBuilder`:
2329

2430
```csharp
25-
Host.CreateDefaultBuilder(args)
26-
.ConfigureWebHostDefaults(webHost =>
27-
{
28-
webHost.UseStartup<Startup>();
29-
})
30-
.ConfigureLogging((hostingContext, loggingBuilder) =>
31-
{
32-
loggingBuilder.AddFile("Logs/myapp-{Date}.txt");
33-
})
34-
.Build();
35-
```
36-
37-
Or, alternatively, with [Minimal APIs](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis):
38-
39-
```csharp
40-
var builder = WebApplication.CreateBuilder(args);
41-
42-
builder.Logging.AddFile("Logs/myapp-{Date}.txt");
43-
// Add other services to the container.
44-
<...>
31+
builder.Services.AddLogging(logging =>
32+
{
33+
logging.AddFile("Logs/myapp-{Date}.txt");
34+
});
4535

46-
var app = builder.Build();
47-
<...>
4836
```
4937

5038
**Done!** The framework will inject `ILogger` instances into controllers and other classes:
@@ -174,7 +162,7 @@ In addition to the properties shown above, the `"Logging"` configuration support
174162

175163
### Using the full Serilog API
176164

177-
This package is opinionated, providing the most common/recommended options supported by Serilog. For more sophisticated configuration, using Serilog directly is recommened. See the instructions in [Serilog.AspNetCore](https://github.com/serilog/serilog-aspnetcore) to get started.
165+
This package is opinionated, providing the most common/recommended options supported by Serilog. For more sophisticated configuration, using Serilog directly is recommended. See the instructions in [Serilog.AspNetCore](https://github.com/serilog/serilog-aspnetcore) to get started.
178166

179167
The following packages are used to provide `loggingBuilder.AddFile()`:
180168

appveyor.yml

-23
This file was deleted.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<GenerateDocumentationFile>false</GenerateDocumentationFile>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
11+
<ProjectReference Include="..\..\src\Serilog.Extensions.Logging.File\Serilog.Extensions.Logging.File.csproj" />
12+
</ItemGroup>
13+
14+
</Project>

example/ConsoleApp1/Program.cs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Microsoft.Extensions.Logging;
3+
4+
var services = new ServiceCollection();
5+
6+
services.AddLogging(logging =>
7+
{
8+
logging.AddConsole();
9+
logging.AddFile("logs/myapp-{Date}.txt");
10+
});
11+
12+
using var serviceProvider = services.BuildServiceProvider();
13+
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
14+
15+
var startTime = DateTimeOffset.UtcNow;
16+
logger.LogInformation(1, "Started at {StartTime} and 0x{Hello:X} is hex of 42", startTime, 42);
17+
18+
try
19+
{
20+
throw new Exception("Boom!");
21+
}
22+
catch (Exception ex)
23+
{
24+
logger.LogCritical(ex, "Unexpected critical error starting application");
25+
}
26+
27+
using (logger.BeginScope("Main"))
28+
{
29+
logger.LogInformation("Waiting for user input");
30+
var key = Console.Read();
31+
logger.LogInformation("User pressed {@KeyInfo}", new { Key = key, KeyChar = (char)key });
32+
}
33+
34+
logger.LogInformation("Stopping");
35+

example/WebApplication/.bowerrc

-3
This file was deleted.

0 commit comments

Comments
 (0)