Skip to content

Commit 7aa0cb1

Browse files
committed
Upgrade project to .NET 10 and Serilog batching sink
Updates target frameworks to include .NET 10.0 across the library and samples. Refactors the Exceptionless sink to implement `IBatchedLogEventSink`, improving efficiency by processing log events in batches. Modernizes sample applications to use ASP.NET Core Minimal APIs and demonstrates proper async flushing of logs. Also includes various dependency updates for GitHub Actions and NuGet packages, and modernizes CI package publishing.
1 parent 17915bf commit 7aa0cb1

15 files changed

Lines changed: 202 additions & 206 deletions

File tree

.github/workflows/build-linux.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- name: Checkout
10-
uses: actions/checkout@v4
10+
uses: actions/checkout@v6
1111
with:
1212
fetch-depth: 0
1313
- name: Setup .NET Core
14-
uses: actions/setup-dotnet@v4
14+
uses: actions/setup-dotnet@v5
1515
with:
16-
dotnet-version: 8.x
16+
dotnet-version: |
17+
8.x
18+
10.x
1719
- name: Build Reason
1820
run: "echo ref: ${{github.ref}} event: ${{github.event_name}}"
1921
- name: Build Version
2022
shell: bash
2123
run: |
22-
dotnet tool install --global minver-cli --version 5.0.0
24+
dotnet tool install --global minver-cli --version 7.0.0
2325
version=$(minver --tag-prefix v)
2426
echo "MINVERVERSIONOVERRIDE=$version" >> $GITHUB_ENV
2527
- name: Build

.github/workflows/build-osx.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ jobs:
77
runs-on: macOS-latest
88
steps:
99
- name: Checkout
10-
uses: actions/checkout@v4
10+
uses: actions/checkout@v6
1111
with:
1212
fetch-depth: 0
1313
- name: Setup .NET Core
14-
uses: actions/setup-dotnet@v4
14+
uses: actions/setup-dotnet@v5
1515
with:
16-
dotnet-version: 8.x
16+
dotnet-version: |
17+
8.x
18+
10.x
1719
- name: Build Reason
1820
run: "echo ref: ${{github.ref}} event: ${{github.event_name}}"
1921
- name: Build Version
2022
shell: bash
2123
run: |
22-
dotnet tool install --global minver-cli --version 5.0.0
24+
dotnet tool install --global minver-cli --version 7.0.0
2325
version=$(minver --tag-prefix v)
2426
echo "MINVERVERSIONOVERRIDE=$version" >> $GITHUB_ENV
2527
- name: Build

.github/workflows/build-windows.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ jobs:
77
runs-on: windows-latest
88
steps:
99
- name: Checkout
10-
uses: actions/checkout@v4
10+
uses: actions/checkout@v6
1111
with:
1212
fetch-depth: 0
1313
- name: Setup .NET Core
14-
uses: actions/setup-dotnet@v4
14+
uses: actions/setup-dotnet@v5
1515
with:
16-
dotnet-version: 8.x
16+
dotnet-version: |
17+
8.x
18+
10.x
1719
- name: Build Reason
1820
run: "echo ref: ${{github.ref}} event: ${{github.event_name}}"
1921
- name: Build Version
2022
shell: bash
2123
run: |
22-
dotnet tool install --global minver-cli --version 5.0.0
24+
dotnet tool install --global minver-cli --version 7.0.0
2325
version=$(minver --tag-prefix v)
2426
echo "MINVERVERSIONOVERRIDE=$version" >> $GITHUB_ENV
2527
- name: Build
@@ -29,18 +31,15 @@ jobs:
2931
- name: Package
3032
if: github.event_name != 'pull_request'
3133
run: dotnet pack --configuration Release --no-build Serilog.Sinks.Exceptionless.slnx
32-
- name: Install GitHub Package Tool
33-
if: github.event_name != 'pull_request'
34-
run: dotnet tool install gpr -g
3534
- name: Publish CI Packages
3635
shell: bash
3736
if: github.event_name != 'pull_request'
3837
run: |
39-
for package in $(find -name "*.nupkg" | grep "minver" -v); do
38+
for package in $(find . -name "*.nupkg" | grep "minver" -v); do
4039
echo "${0##*/}": Pushing $package...
4140
4241
# GitHub
43-
gpr push $package -k ${{ secrets.GITHUB_TOKEN }} || true
42+
dotnet nuget push $package --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/Exceptionless/index.json --skip-duplicate || true
4443
done
4544
- name: Publish Release Packages
4645
shell: bash

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,14 @@ _logger.Log(logLevel, eventId, state, exception, formatter);
4545

4646
* [Documentation](https://github.com/serilog/serilog/wiki)
4747

48-
Copyright © 2023 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html).
48+
### Flushing Background Queues
49+
50+
Exceptionless events are queued in memory and submitted to the API in the background. If your application process crashes or exits, pending logs may be lost. You should always ensure that you flush the Serilog sink when shutting down:
51+
52+
```csharp
53+
await Log.CloseAndFlushAsync(); // Recommended for modern async apps
54+
// or
55+
Log.CloseAndFlush();
56+
```
57+
58+
Copyright © 2026 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html).
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFrameworks>net8.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77
<ItemGroup>
88
<ProjectReference Include="..\..\src\Serilog.Sinks.Exceptionless\Serilog.Sinks.Exceptionless.csproj" />
99
</ItemGroup>
1010
<ItemGroup>
11-
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
11+
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
1212
</ItemGroup>
1313
</Project>

sample/ConsoleDemo/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace ConsoleDemo
77
{
88
public class Program
99
{
10-
public static void Main()
10+
public static async System.Threading.Tasks.Task Main()
1111
{
1212
ExceptionlessClient.Default.Startup("API_KEY");
1313

@@ -30,7 +30,7 @@ public static void Main()
3030
Log.Error(ex, "Something went wrong");
3131
}
3232

33-
Log.CloseAndFlush();
33+
await Log.CloseAndFlushAsync();
3434
}
3535

3636
private static void Fail()

sample/SampleWeb/Authentication/TestAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace SampleWeb.Authentication
1111
public class TestAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
1212
{
1313
public TestAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options,
14-
ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
15-
: base(options, logger, encoder, clock)
14+
ILoggerFactory logger, UrlEncoder encoder)
15+
: base(options, logger, encoder)
1616
{
1717
}
1818

sample/SampleWeb/Controllers/ValuesController.cs

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

sample/SampleWeb/Program.cs

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,80 @@
11
using System;
2-
using Microsoft.AspNetCore.Hosting;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Security.Claims;
5+
using Exceptionless;
6+
using Exceptionless.Models;
7+
using Exceptionless.Models.Data;
8+
using Microsoft.AspNetCore.Authentication;
9+
using Microsoft.AspNetCore.Builder;
10+
using Microsoft.AspNetCore.Mvc;
11+
using Microsoft.Extensions.DependencyInjection;
312
using Microsoft.Extensions.Hosting;
13+
using Microsoft.Extensions.Logging;
14+
using SampleWeb.Authentication;
415
using Serilog;
16+
using Serilog.Context;
517

6-
namespace SampleWeb
18+
var builder = WebApplication.CreateBuilder(args);
19+
20+
builder.Host.UseSerilog((hostingContext, services, loggerConfiguration) => loggerConfiguration
21+
.ReadFrom.Configuration(hostingContext.Configuration)
22+
.Enrich.FromLogContext()
23+
.WriteTo.Debug()
24+
.WriteTo.Console()
25+
.WriteTo.Exceptionless());
26+
27+
builder.Services.AddAuthentication("Test").AddScheme<AuthenticationSchemeOptions, TestAuthenticationHandler>("Test", options => { });
28+
builder.Services.AddAuthorization();
29+
builder.Services.AddHttpContextAccessor();
30+
builder.Services.AddExceptionless("API_KEY");
31+
32+
var app = builder.Build();
33+
34+
app.UseExceptionless();
35+
app.UseSerilogRequestLogging();
36+
app.UseHttpsRedirection();
37+
app.UseAuthentication();
38+
app.UseAuthorization();
39+
40+
app.MapGet("/values", (ClaimsPrincipal user, ILogger<Program> logger) =>
41+
{
42+
using var _ = logger.BeginScope(new Dictionary<string, object> { ["Tags"] = new string[] { "Tag1", "Tag2" } });
43+
logger.LogInformation("Get was called");
44+
45+
return $"[{Activity.Current?.Id}] {user.Identity?.Name}";
46+
});
47+
48+
app.MapGet("/values/advanced-topic-user", (ClaimsPrincipal user, ILogger<Program> logger) =>
49+
{
50+
using (LogContext.PushProperty(Event.KnownDataKeys.UserInfo, new UserInfo(user.Identity?.Name + " Custom", "Test User Full Name"), true))
51+
{
52+
logger.LogInformation("This log event will have a custom user set.");
53+
}
54+
55+
return $"[{Activity.Current?.Id}] {user.Identity?.Name}";
56+
});
57+
58+
app.MapGet("/values/advanced-topic-user-description", ([FromQuery] string description, ClaimsPrincipal user, ILogger<Program> logger) =>
759
{
8-
public class Program
60+
using (LogContext.PushProperty(Event.KnownDataKeys.UserDescription, new UserDescription(user.Identity?.Name, description), true))
961
{
10-
public static void Main(string[] args)
11-
{
12-
CreateHostBuilder(args).Build().Run();
13-
}
14-
15-
public static IHostBuilder CreateHostBuilder(string[] args)
16-
{
17-
return Host.CreateDefaultBuilder(args)
18-
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>())
19-
.UseSerilog((hostingContext, services, loggerConfiguration) => loggerConfiguration
20-
.ReadFrom.Configuration(hostingContext.Configuration)
21-
.Enrich.FromLogContext()
22-
.WriteTo.Debug()
23-
.WriteTo.Console()
24-
.WriteTo.Exceptionless()
25-
);
26-
}
62+
logger.LogError(new Exception("Test"), "This error event will have a user description set on it.");
2763
}
64+
65+
return $"[{Activity.Current?.Id}] {user.Identity?.Name}";
66+
});
67+
68+
try
69+
{
70+
Log.Information("Starting web host");
71+
await app.RunAsync();
72+
}
73+
catch (Exception ex)
74+
{
75+
Log.Fatal(ex, "Host terminated unexpectedly");
76+
}
77+
finally
78+
{
79+
await Log.CloseAndFlushAsync();
2880
}

sample/SampleWeb/SampleWeb.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
44
<IsPackable>false</IsPackable>
55
</PropertyGroup>
66

77
<ItemGroup>
88
<PackageReference Include="Exceptionless.AspNetCore" Version="6.0.4" />
9-
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
9+
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

0 commit comments

Comments
 (0)