Serilog.Sinks.PeriodicBatching 5.0.0-dev-00855

Serilog.Sinks.PeriodicBatching Build status NuGet Version

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 and WriteTo.Sink(IBatchedLogEventSink), not this package which is now only maintained for compatibility reasons.

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);
    }
}

Showing the top 20 packages that depend on Serilog.Sinks.PeriodicBatching.

Packages Downloads
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
143
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
100
Serilog.Sinks.Slack
Serilog sink for Slack
77
Serilog.Sinks.Slack
Serilog sink for Slack
58
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
45
Serilog.Sinks.Slack
Serilog sink for Slack
22
Serilog.Sinks.Slack
Serilog sink for Slack
20
Serilog.Sinks.Slack
Serilog.Sinks.Slack
16
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
14
Serilog.Sinks.MSSqlServer
A Serilog sink that writes events to Microsoft SQL Server and Azure SQL
14
Serilog.Sinks.Seq
A Serilog sink that writes events to Seq using newline-delimited JSON and HTTP/HTTPS.
14
Serilog.Sinks.MSSqlServer
A Serilog sink that writes events to Microsoft SQL Server
14
Serilog.Sinks.Slack
Serilog sink for Slack
14
Serilog.Sinks.MSSqlServer
A Serilog sink that writes events to Microsoft SQL Server and Azure SQL
13
Serilog.Sinks.Seq
Serilog sink that writes to the Seq event server over HTTP/S.
13
Serilog.Sinks.MSSqlServer
A Serilog sink that writes events to Microsoft SQL Server
13
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
13

.NET Framework 4.6.2

.NET Framework 4.7.1

.NET 6.0

.NET 8.0

.NET Standard 2.0

Version Downloads Last updated
5.0.1-dev-00860 14 10/10/2024
5.0.0 15 10/10/2024
5.0.0-dev-00855 11 10/10/2024
4.1.2-dev-00851 17 10/10/2024
4.1.1 11 10/10/2024
4.1.1-dev-00845 14 10/10/2024
4.1.0 13 10/10/2024
4.1.0-dev-00840 15 10/10/2024
4.0.2-dev-00838 9 10/10/2024
4.0.1 14 10/10/2024
4.0.1-dev-00832 15 10/10/2024
4.0.0 14 06/17/2024
4.0.0-dev-00824 13 10/10/2024
4.0.0-dev-00821 15 10/10/2024
3.1.1-dev-00804 16 03/17/2024
3.1.1-dev-00801 15 10/10/2024
3.1.0 17 12/02/2022
3.1.0-dev-00796 13 10/10/2024
3.0.0 14 10/10/2024
3.0.0-dev-00792 14 10/10/2024
2.3.1 96 03/21/2022
2.3.1-dev-00785 10 10/10/2024
2.3.1-dev-00780 14 10/10/2024
2.3.1-dev-00776 15 10/10/2024
2.3.1-dev-00774 15 10/10/2024
2.3.0 222 12/07/2021
2.3.0-dev-00765 14 10/10/2024
2.3.0-dev-00762 12 10/10/2024
2.3.0-dev-00760 15 10/10/2024
2.2.1-dev-00758 14 10/10/2024
2.2.1-dev-00755 15 10/10/2024
2.2.0 12 10/10/2024
2.2.0-dev-00748 12 10/10/2024
2.2.0-dev-00740 10 10/10/2024
2.1.1 14 05/12/2022
2.1.1-dev-00732 10 10/10/2024
2.1.1-dev-00729 12 10/10/2024
2.1.1-dev-00725 15 10/10/2024
2.1.0 11 10/10/2024
2.1.0-dev-00720 11 10/10/2024
2.0.2-dev-00719 14 10/10/2024
2.0.1 11 10/10/2024
2.0.1-dev-00714 13 10/10/2024
2.0.0 13 10/10/2024
2.0.0-rc-707 10 10/10/2024
2.0.0-rc-705 10 10/10/2024
2.0.0-beta-702 10 10/10/2024
2.0.0-beta-700 10 10/10/2024
2.0.0-beta-519 16 10/10/2024
2.0.0-beta-516 16 10/10/2024
2.0.0-beta-513 14 10/06/2024
2.0.0-beta-511 13 10/10/2024
2.0.0-beta-509 13 10/10/2024
2.0.0-beta-507 13 10/10/2024
2.0.0-beta-505 10 10/10/2024
2.0.0-beta-502 14 10/10/2024
2.0.0-beta-499 15 10/10/2024
2.0.0-beta-495 14 10/10/2024
2.0.0-beta-494 12 10/10/2024
2.0.0-beta-493 16 10/10/2024
2.0.0-beta-487 13 10/10/2024
2.0.0-beta-486 11 10/10/2024
2.0.0-beta-479 16 10/10/2024
2.0.0-beta-478 11 10/10/2024
2.0.0-beta-465 15 10/10/2024