Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore
5.1.1
dotnet add package Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore --version 5.1.1
NuGet\Install-Package Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore -Version 5.1.1
<PackageReference Include="Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore" Version="5.1.1" />
<PackageVersion Include="Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore" Version="5.1.1" />
<PackageReference Include="Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore" />
paket add Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore --version 5.1.1
#r "nuget: Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore, 5.1.1"
#:package Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore@5.1.1
#addin nuget:?package=Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore&version=5.1.1
#tool nuget:?package=Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore&version=5.1.1
Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore
Provides ASP.NET Core integration for Waystone.WideLogEvents, allowing you to
automatically capture request and response details and include them in your
Serilog logs.
Installation
Install the NuGet package:
dotnet add package Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore
This package transitively includes Waystone.WideLogEvents and
Serilog.Enrichers.Waystone.WideLogEvents.
Usage
1. Configure Serilog
In your Program.cs, configure Serilog to use the Wide Log Events enricher and
the sampling filter:
using Serilog;
using Serilog.Enrichers.Waystone.WideLogEvents;
builder.Host.UseSerilog((context, config) => config
.Enrich.FromWideLogEventsContext()
.Filter.WithWideLogEventsSampling()
.ReadFrom.Configuration(context.Configuration));
2. Register Middleware
Add the UseWideLogEventsContext middleware to your application pipeline. This
middleware should typically be placed early in the pipeline to capture as much
information as possible.
using Serilog.Enrichers.Waystone.WideLogEvents.AspNetCore;
var app = builder.Build();
app.UseWideLogEventsContext();
// ... other middleware
3. Use in Endpoints
You can now push properties to the WideLogEventContext anywhere in your
request lifecycle (e.g., in Controllers, Minimal API handlers, or Services):
using Waystone.WideLogEvents;
app.MapGet("/weatherforecast", () =>
{
var forecast = // ... get forecast
// This property will be included in the final "wide" log for this request
WideLogEventContext.PushProperty("ForecastCount", forecast.Length);
return forecast;
});
Configuration Options
You can customize the sampling behavior of the log events by configuring the sampling filter in Serilog:
builder.Host.UseSerilog((context, config) => config
.Enrich.FromWideLogEventsContext()
.Filter.WithWideLogEventsSampling(options =>
{
options.InformationSampleRate = 0.5; // Log 50% of information logs
options.ErrorSampleRate = 1.0; // Log 100% of error logs
// Custom random provider for sampling decisions
options.RandomDoubleProvider = new MyRandomProvider();
})
.ReadFrom.Configuration(context.Configuration));
Custom Random Provider
By default, the sampling filter uses an internal implementation that creates a
new Random instance. If you want to use a specific random number generator
(like Random.Shared in .NET 6+), you can implement IRandomDoubleProvider:
public class MyRandomProvider : IRandomDoubleProvider
{
public double NextDouble() => Random.Shared.NextDouble();
}
Features
- Automatic Request Capture: Captures Method, Path, Scheme, Host, ContentType, etc.
- Automatic Response Capture: Captures StatusCode, ContentType, etc.
- Duration Tracking: Logs the total time taken for the request to be processed.
- Sampling: Built-in support for sampling logs based on log level.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Serilog.Enrichers.Waystone.WideLogEvents (>= 5.1.1)
-
net8.0
- Serilog.Enrichers.Waystone.WideLogEvents (>= 5.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 5.1.1 | 692 | 2/6/2026 |
| 5.1.0 | 128 | 2/6/2026 |
| 5.1.0-wide-events.5 | 382 | 2/4/2026 |
| 5.1.0-wide-events.4 | 73 | 2/4/2026 |
| 5.1.0-wide-events.3 | 72 | 2/2/2026 |
| 5.1.0-wide-events.2 | 75 | 2/2/2026 |
| 5.1.0-wide-events.1 | 79 | 2/1/2026 |