Serilog.Sinks.PeriodicBatching 5.0.1-dev-00860

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.

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

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

Packages Downloads
Microsoft.Extensions.Logging.AzureAppServices
Logger implementation to support Azure App Services 'Diagnostics logs' and 'Log stream' features.
24
Microsoft.Extensions.Logging.AzureAppServices
Logger implementation to support Azure App Services 'Diagnostics logs' and 'Log stream' features.
32
Serilog.Sinks.Email
Send Serilog events as SMTP email using MailKit.
30
Serilog.Sinks.Email
Send Serilog events as SMTP email using MailKit.
38
Serilog.Sinks.Email
The file sink for Serilog
24
Serilog.Sinks.Email
The file sink for Serilog
32
Serilog.Sinks.Email
The file sink for Serilog
33
Serilog.Sinks.Seq
A Serilog sink that writes events to Seq using newline-delimited JSON and HTTP/HTTPS.
31
Serilog.Sinks.Seq
Serilog sink that writes to the Seq event server over HTTP/S.
25
Serilog.Sinks.Seq
Serilog sink that writes to the Seq event server over HTTP/S.
28
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
24
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
26
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
31
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
56
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
93
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
173
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
332
Serilog.Sinks.Seq
Serilog sink that writes to the Seq log server over HTTP/HTTPS.
474

.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 27 07/06/2024
5.0.0 23 06/06/2024
5.0.0-dev-00855 22 06/07/2024
4.1.2-dev-00851 26 06/04/2024
4.1.1 22 05/29/2024
4.1.1-dev-00845 24 05/27/2024
4.1.0 29 05/12/2024
4.1.0-dev-00840 19 05/12/2024
4.0.2-dev-00838 21 05/12/2024
4.0.1 27 03/15/2024
4.0.1-dev-00832 23 03/15/2024
4.0.0 26 03/13/2024
4.0.0-dev-00824 29 02/08/2024
4.0.0-dev-00821 35 02/08/2024
3.1.1-dev-00804 19 02/08/2024
3.1.1-dev-00801 30 02/08/2024
3.1.0 153 10/10/2022
3.1.0-dev-00796 38 02/08/2024
3.0.0 53 09/20/2022
3.0.0-dev-00792 23 02/08/2024
2.3.1 76 04/15/2022
2.3.1-dev-00785 24 02/08/2024
2.3.1-dev-00780 27 02/08/2024
2.3.1-dev-00776 24 02/08/2024
2.3.1-dev-00774 27 02/08/2024
2.3.0 500 02/26/2021
2.3.0-dev-00765 22 02/08/2024
2.3.0-dev-00762 26 02/08/2024
2.3.0-dev-00760 25 02/08/2024
2.2.1-dev-00758 26 02/08/2024
2.2.1-dev-00755 20 02/08/2024
2.2.0 29 02/10/2020
2.2.0-dev-00748 27 02/08/2024
2.2.0-dev-00740 27 02/08/2024
2.1.1 24 07/04/2020
2.1.1-dev-00732 28 02/08/2024
2.1.1-dev-00729 22 02/08/2024
2.1.1-dev-00725 35 02/08/2024
2.1.0 27 02/08/2024
2.1.0-dev-00720 23 02/08/2024
2.0.2-dev-00719 25 02/08/2024
2.0.1 25 02/08/2024
2.0.1-dev-00714 24 02/08/2024
2.0.0 42 02/08/2024
2.0.0-rc-707 28 02/08/2024
2.0.0-rc-705 25 02/08/2024
2.0.0-beta-702 24 02/08/2024
2.0.0-beta-700 26 02/08/2024
2.0.0-beta-519 23 02/08/2024
2.0.0-beta-516 26 02/08/2024
2.0.0-beta-513 29 02/08/2024
2.0.0-beta-511 24 02/08/2024
2.0.0-beta-509 22 02/08/2024
2.0.0-beta-507 29 02/08/2024
2.0.0-beta-505 22 02/08/2024
2.0.0-beta-502 22 02/08/2024
2.0.0-beta-499 26 02/08/2024
2.0.0-beta-495 20 02/08/2024
2.0.0-beta-494 19 02/08/2024
2.0.0-beta-493 27 02/08/2024
2.0.0-beta-487 29 02/08/2024
2.0.0-beta-486 29 02/08/2024
2.0.0-beta-479 31 02/08/2024
2.0.0-beta-478 31 02/08/2024
2.0.0-beta-465 23 02/08/2024