Serilog.Sinks.PeriodicBatching 4.1.1-dev-00845

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.

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.
46
Microsoft.Extensions.Logging.AzureAppServices
Logger implementation to support Azure App Services 'Diagnostics logs' and 'Log stream' features.
41
Microsoft.Extensions.Logging.AzureAppServices
Logger implementation to support Azure App Services 'Diagnostics logs' and 'Log stream' features.
36
Microsoft.Extensions.Logging.AzureAppServices
Diagnostics logger for Azure WebApps
34
Microsoft.Extensions.Logging.AzureAppServices
Logger implementation to support Azure App Services 'Diagnostics logs' and 'Log stream' features.
33
Microsoft.Extensions.Logging.AzureAppServices
Logger implementation to support Azure App Services 'Diagnostics logs' and 'Log stream' features.
32

.NET Framework 4.6.2

.NET 6.0

.NET Standard 2.0

Version Downloads Last updated
5.0.1-dev-00860 41 8/11/2024
5.0.0 44 8/20/2024
5.0.0-dev-00855 34 7/10/2024
4.1.2-dev-00851 34 8/19/2024
4.1.1 42 7/26/2024
4.1.1-dev-00845 34 8/11/2024
4.1.0 37 8/21/2024
4.1.0-dev-00840 36 7/21/2024
4.0.2-dev-00838 38 7/12/2024
4.0.1 42 4/23/2024
4.0.1-dev-00832 43 3/28/2024
4.0.0 40 3/8/2024
4.0.0-dev-00824 42 3/8/2024
4.0.0-dev-00821 37 3/8/2024
3.1.1-dev-00804 39 3/8/2024
3.1.1-dev-00801 39 3/8/2024
3.1.0 38 3/8/2024
3.1.0-dev-00796 37 3/8/2024
3.0.0 38 3/8/2024
3.0.0-dev-00792 37 3/8/2024
2.3.1 36 3/8/2024
2.3.1-dev-00785 37 3/8/2024
2.3.1-dev-00780 35 3/8/2024
2.3.1-dev-00776 36 3/8/2024
2.3.1-dev-00774 37 3/8/2024
2.3.0 37 3/8/2024
2.3.0-dev-00765 36 3/8/2024
2.3.0-dev-00762 39 3/8/2024
2.3.0-dev-00760 40 3/8/2024
2.2.1-dev-00758 40 3/8/2024
2.2.1-dev-00755 41 3/8/2024
2.2.0 38 3/8/2024
2.2.0-dev-00748 35 3/8/2024
2.2.0-dev-00740 44 3/8/2024
2.1.1 42 3/8/2024
2.1.1-dev-00732 35 3/8/2024
2.1.1-dev-00729 41 3/8/2024
2.1.1-dev-00725 39 3/8/2024
2.1.0 41 3/8/2024
2.1.0-dev-00720 39 3/8/2024
2.0.2-dev-00719 38 3/8/2024
2.0.1 51 3/8/2024
2.0.1-dev-00714 38 3/8/2024
2.0.0 45 3/8/2024
2.0.0-rc-707 44 3/8/2024
2.0.0-rc-705 47 3/8/2024
2.0.0-beta-702 37 3/8/2024
2.0.0-beta-700 34 3/8/2024
2.0.0-beta-519 37 3/8/2024
2.0.0-beta-516 40 3/8/2024
2.0.0-beta-513 33 3/8/2024
2.0.0-beta-511 40 3/8/2024
2.0.0-beta-509 39 3/8/2024
2.0.0-beta-507 45 3/8/2024
2.0.0-beta-505 37 3/8/2024
2.0.0-beta-502 36 3/8/2024
2.0.0-beta-499 36 3/8/2024
2.0.0-beta-495 39 3/8/2024
2.0.0-beta-494 41 3/8/2024
2.0.0-beta-493 40 3/8/2024
2.0.0-beta-487 46 3/8/2024
2.0.0-beta-486 37 3/8/2024
2.0.0-beta-479 43 3/8/2024
2.0.0-beta-478 45 3/8/2024
2.0.0-beta-465 37 3/8/2024