Serilog.Sinks.PeriodicBatching
5.0.1-dev-00860
Prefix Reserved
dotnet add package Serilog.Sinks.PeriodicBatching --version 5.0.1-dev-00860
NuGet\Install-Package Serilog.Sinks.PeriodicBatching -Version 5.0.1-dev-00860
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="5.0.1-dev-00860" />
paket add Serilog.Sinks.PeriodicBatching --version 5.0.1-dev-00860
#r "nuget: Serilog.Sinks.PeriodicBatching, 5.0.1-dev-00860"
// Install Serilog.Sinks.PeriodicBatching as a Cake Addin #addin nuget:?package=Serilog.Sinks.PeriodicBatching&version=5.0.1-dev-00860&prerelease // Install Serilog.Sinks.PeriodicBatching as a Cake Tool #tool nuget:?package=Serilog.Sinks.PeriodicBatching&version=5.0.1-dev-00860&prerelease
Serilog.Sinks.PeriodicBatching
A wrapper for Serilog sinks that asynchronously emits events in batches, useful when logging to a slow and/or remote target.
[!IMPORTANT] Serilog 4.x and later versions support batching natively. New projects should use Serilog's
IBatchedLogEventSink
andWriteTo.Sink(IBatchedLogEventSink)
, not this package which is now only maintained for compatibility reasons.
Updating for Serilog v4+
First, update your Serilog package reference to the latest published version.
This example is from Serilog.Sinks.Postgresql.Alternative. Old code:
var batchingOptions = new PeriodicBatchingSinkOptions()
{
BatchSizeLimit = postgresOptions.BatchSizeLimit,
Period = postgresOptions.Period,
QueueLimit = postgresOptions.QueueLimit
};
var batchingSink = new PeriodicBatchingSink(new PostgreSqlSink(postgresOptions), batchingOptions);
return sinkConfiguration.Sink(batchingSink, restrictedToMinimumLevel, levelSwitch);
New code:
var batchingOptions = new BatchingOptions()
{
BatchSizeLimit = postgresOptions.BatchSizeLimit,
BufferingTimeLimit = postgresOptions.Period,
QueueLimit = postgresOptions.QueueLimit
};
return sinkConfiguration.Sink(
new PostgreSqlSink(postgresOptions), batchingOptions, restrictedToMinimumLevel, levelSwitch);
When you're done, don't forget to remove the Serilog.Sinks.PeriodicBatching package dependency.
Getting started
Sinks that, for performance reasons, need to emit events in batches, can be implemented using PeriodicBatchingSink
from this package.
First, install the package into your Sink project:
dotnet add package Serilog.Sinks.PeriodicBatching
Then, instead of implementing Serilog's ILogEventSink
, implement IBatchedLogEventSink
in your sink class:
class ExampleBatchedSink : IBatchedLogEventSink
{
public async Task EmitBatchAsync(IEnumerable<LogEvent> batch)
{
foreach (var logEvent in batch)
Console.WriteLine(logEvent);
}
public Task OnEmptyBatchAsync() { }
}
Finally, in your sink's configuration method, construct a PeriodicBatchingSink
that wraps your batched sink:
public static class LoggerSinkExampleConfiguration
{
public static LoggerConfiguration Example(this LoggerSinkConfiguration loggerSinkConfiguration)
{
var exampleSink = new ExampleBatchedSink();
var batchingOptions = new PeriodicBatchingSinkOptions
{
BatchSizeLimit = 100,
Period = TimeSpan.FromSeconds(2),
EagerlyEmitFirstEvent = true,
QueueLimit = 10000
};
var batchingSink = new PeriodicBatchingSink(exampleSink, batchingOptions);
return loggerSinkConfiguration.Sink(batchingSink);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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. |
.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 is compatible. 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 (267)
Showing the top 5 NuGet packages that depend on Serilog.Sinks.PeriodicBatching:
Package | Downloads |
---|---|
Serilog.Sinks.Elasticsearch
Serilog sink for Elasticsearch |
|
Serilog.Sinks.Datadog.Logs
Serilog Sink that sends log events to Datadog https://www.datadoghq.com/ |
|
Serilog.Sinks.AwsCloudWatch
A Serilog sink that logs to AWS CloudWatch |
|
Serilog.Sinks.MongoDB
The MongoDB sink for Serilog |
|
Serilog.Sinks.Slack
Serilog sink for Slack |
GitHub repositories (11)
Showing the top 5 popular GitHub repositories that depend on Serilog.Sinks.PeriodicBatching:
Repository | Stars |
---|---|
dotnetcore/DotnetSpider
DotnetSpider, a .NET standard web crawling library. It is lightweight, efficient and fast high-level web crawling & scraping framework
|
|
chocolatey/ChocolateyGUI
A delicious GUI for Chocolatey
|
|
smartstore/Smartstore
A modular, scalable and ultra-fast open-source all-in-one eCommerce platform built on ASP.NET Core 7
|
|
serilog-contrib/serilog-sinks-elasticsearch
A Serilog sink that writes events to Elasticsearch
|
|
trimble-oss/dba-dash
DBA Dash - SQL Server Monitoring Tool
|
Version | Downloads | Last updated |
---|---|---|
5.0.1-dev-00860 | 3,007 | 7/2/2024 |
5.0.0 | 1,403,479 | 6/5/2024 |
5.0.0-dev-00855 | 182 | 6/5/2024 |
4.1.2-dev-00851 | 214 | 5/30/2024 |
4.1.1 | 266,451 | 5/28/2024 |
4.1.1-dev-00845 | 373 | 5/22/2024 |
4.1.0 | 1,318,528 | 5/3/2024 |
4.1.0-dev-00840 | 1,374 | 5/1/2024 |
4.0.2-dev-00838 | 204 | 5/1/2024 |
4.0.1 | 801,214 | 3/15/2024 |
4.0.1-dev-00832 | 317 | 3/14/2024 |
4.0.0 | 5,302,163 | 2/22/2024 |
4.0.0-dev-00824 | 2,500 | 2/2/2024 |
4.0.0-dev-00821 | 40,066 | 1/1/2024 |
3.1.1-dev-00804 | 7,685 | 4/15/2023 |
3.1.1-dev-00801 | 9,845 | 9/27/2022 |
3.1.0 | 46,277,858 | 9/27/2022 |
3.1.0-dev-00796 | 1,878 | 9/15/2022 |
3.0.0 | 8,472,035 | 9/13/2022 |
3.0.0-dev-00792 | 1,478 | 9/12/2022 |
2.3.1 | 10,598,983 | 1/7/2022 |
2.3.1-dev-00785 | 969 | 1/7/2022 |
2.3.1-dev-00780 | 28,708 | 1/6/2021 |
2.3.1-dev-00776 | 4,737 | 7/23/2020 |
2.3.1-dev-00774 | 1,898 | 6/1/2020 |
2.3.0 | 72,195,740 | 2/28/2020 |
2.3.0-dev-00765 | 1,618 | 2/17/2020 |
2.3.0-dev-00762 | 153,803 | 2/16/2020 |
2.3.0-dev-00760 | 35,126 | 2/14/2020 |
2.2.1-dev-00758 | 1,527 | 2/13/2020 |
2.2.1-dev-00755 | 22,187 | 7/10/2019 |
2.2.0 | 22,294,278 | 5/2/2019 |
2.2.0-dev-00748 | 1,635 | 5/2/2019 |
2.2.0-dev-00740 | 4,695 | 1/28/2019 |
2.1.1 | 112,836,304 | 6/20/2017 |
2.1.1-dev-00732 | 1,915 | 6/20/2017 |
2.1.1-dev-00729 | 4,651 | 3/13/2017 |
2.1.1-dev-00725 | 181,913 | 10/26/2016 |
2.1.0 | 13,082,724 | 10/25/2016 |
2.1.0-dev-00720 | 2,430 | 9/29/2016 |
2.0.2-dev-00719 | 1,904 | 9/28/2016 |
2.0.1 | 364,996 | 9/20/2016 |
2.0.1-dev-00714 | 2,273 | 9/12/2016 |
2.0.0 | 6,144,664 | 6/27/2016 |
2.0.0-rc-707 | 6,479 | 5/17/2016 |
2.0.0-rc-705 | 1,862 | 5/17/2016 |
2.0.0-beta-702 | 1,899 | 4/20/2016 |
2.0.0-beta-700 | 10,577 | 3/23/2016 |
2.0.0-beta-519 | 2,071 | 3/16/2016 |
2.0.0-beta-516 | 1,794 | 3/15/2016 |
2.0.0-beta-513 | 1,815 | 3/15/2016 |
2.0.0-beta-511 | 1,769 | 3/14/2016 |
2.0.0-beta-509 | 1,730 | 3/13/2016 |
2.0.0-beta-507 | 2,072 | 3/1/2016 |
2.0.0-beta-505 | 4,853 | 2/25/2016 |
2.0.0-beta-502 | 1,898 | 2/22/2016 |
2.0.0-beta-499 | 1,917 | 2/21/2016 |
2.0.0-beta-495 | 1,814 | 2/19/2016 |
2.0.0-beta-494 | 1,787 | 2/18/2016 |
2.0.0-beta-493 | 1,763 | 2/18/2016 |
2.0.0-beta-487 | 1,978 | 2/16/2016 |
2.0.0-beta-486 | 2,021 | 2/11/2016 |
2.0.0-beta-479 | 1,879 | 2/9/2016 |
2.0.0-beta-478 | 1,853 | 2/9/2016 |
2.0.0-beta-465 | 3,618 | 1/26/2016 |