
Security News
Node.js Homepage Adds Paid Support Link, Prompting Contributor Pushback
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Serilog.Sinks.PeriodicBatching
Advanced tools
Buffer batches of log events to be flushed asynchronously.
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.
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.
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);
}
}
FAQs
Buffer batches of log events to be flushed asynchronously.
We found that serilog.sinks.periodicbatching demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.
Research
Security News
The Socket Research Team investigates a malicious Python typosquat of a popular password library that forces Windows shutdowns when input is incorrect.