Serilog.Sinks.Intercepter
1.0.3
dotnet add package Serilog.Sinks.Intercepter --version 1.0.3
NuGet\Install-Package Serilog.Sinks.Intercepter -Version 1.0.3
<PackageReference Include="Serilog.Sinks.Intercepter" Version="1.0.3" />
<PackageVersion Include="Serilog.Sinks.Intercepter" Version="1.0.3" />
<PackageReference Include="Serilog.Sinks.Intercepter" />
paket add Serilog.Sinks.Intercepter --version 1.0.3
#r "nuget: Serilog.Sinks.Intercepter, 1.0.3"
#:package Serilog.Sinks.Intercepter@1.0.3
#addin nuget:?package=Serilog.Sinks.Intercepter&version=1.0.3
#tool nuget:?package=Serilog.Sinks.Intercepter&version=1.0.3
Modify, filter, buffer event logs. Buffer log messages and conditionally output them based on later events.
A wrapper for other Serilog sinks. This sink allows you to "intercept" log events just as they are written to a wrapped sink. This is used to modify, filter, buffer event logs. This is especially suited to reducing log volume, for example only writing logs when an error has occurred.
Getting started
Assuming you have already installed the target sink, such as the console sink, move the wrapped sink's configuration within a WriteTo.Intercepter()
statement:
Log.Logger = new LoggerConfiguration()
.WriteTo.Intercepter(x => x.Console())
// Other logger configuration
.CreateLogger()
Log.Information("Continue to use the log as normal");
// At application shutdown
Log.CloseAndFlush();
or if using Serilog.Settings.Configuration JSON:
{
"Serilog": {
"WriteTo": [{
"Name": "Intercepter",
"Args": {
"configure": [{
"Name": "Console"
}]
}
}]
}
}
Whilst no Intercepter has been set, all log messages will be sent onwards to the wrapped sink (Console
in this case).
LogLevelBuffer Intercepter
This Intercepter is designed to reduce log volume by storing log events and only writing when an error level log event is received.
// add the Intercepter
using (IntercepterContext.PushLogLevelBuffer(Serilog.Events.LogEventLevel.Error))
{
Log.Information("This log is stored by the intercepter.");
Log.Error("On this error, this and all previous log events are sent to the wrapped sink");
Log.Information("As there has already been an error, this is sent to");
}
Can be used per application request to only write the logs of requests where there was an error.
Log event ordering
In the event of any buffering, the log events sent to the output are in the original order and with the original timestamps.
ASP.NET Core integration
Please see here for details.
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 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 is compatible. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Adding direct support for .Net 8 & 9.
- Marking as IsAotCompatible