Serilog.Sinks.Router
1.2.0
See the version list below for details.
dotnet add package Serilog.Sinks.Router --version 1.2.0
NuGet\Install-Package Serilog.Sinks.Router -Version 1.2.0
<PackageReference Include="Serilog.Sinks.Router" Version="1.2.0" />
<PackageVersion Include="Serilog.Sinks.Router" Version="1.2.0" />
<PackageReference Include="Serilog.Sinks.Router" />
paket add Serilog.Sinks.Router --version 1.2.0
#r "nuget: Serilog.Sinks.Router, 1.2.0"
#:package Serilog.Sinks.Router@1.2.0
#addin nuget:?package=Serilog.Sinks.Router&version=1.2.0
#tool nuget:?package=Serilog.Sinks.Router&version=1.2.0
Router Sink for Serilog
Uses DynamicExpresso and IOptions tracking to enable dynamic routing of LogEvents between two different sinks.
Targets
- .NET Standard 2.1 (netstandard2.1)
Usage
From inside a ASP.Net Core application:
var builder = WebApplication.CreateBuilder(args);
// To enable dynamic recompilation you must enable the "reloadOnChange" flag.
builder.Configuration.AddJsonFile("logging.json", optional: false, reloadOnChange: true);
builder.Services.AddOptions();
builder.Services.Configure<RouterSinkOptions>(builder.Configuration.GetSection("RouterSink"));
// This example uses the ApplicationInsights sink as the A sink.
builder.Services.AddApplicationInsightsTelemetry();
builder.Host.UseSerilog((context, services, configuration) =>
{
configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.WriteTo.RouterSink(services.GetRequiredService<IOptionsMonitor<RouterSinkOptions>>(), sinkAConf => sinkAConf.ApplicationInsights(services.GetRequiredService<TelemetryConfiguration>(),
TelemetryConverter.Traces), sinkBConf => sinkBConf.Console());
});
Configuration
The current ILogEvent is made implicitly available by the configured DynamicExpresso interpreter.
So accessing the Properties of the ILogEvent is as simple as using Properties[keyForPropertyYouWant].
Simple example based on event level:
This configuration only uses the A sink if the log event level is debug, and everything else will get logged by the B sink.
{
"RouterSink": {
"ShouldEmitSinkAExpression": "Level == LogEventLevel.Debug",
"ShouldEmitSinkBExpression": ""
}
}
More complex example based on request host information:
Now the A sink only logs if the port number from the request host information contains the port 7443. The B sink is currently disabled, but that can be changed dynamically at runtime without restarting the server.
{
"RouterSink": {
"ShouldEmitSinkAExpression": "Properties.Keys.Contains(\"RequestPath\") && Properties.Keys.Contains(\"Host\") && Properties[\"Host\"].ToString().Contains(\":7443\")",
"ShouldEmitSinkBExpression": "false"
}
}
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- DynamicExpresso.Core (>= 2.16.0)
- Microsoft.Extensions.Options (>= 7.0.1)
- Serilog (>= 2.12.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release.