Skip to content

Commit

Permalink
Merge pull request #134 from nblumhardt/dispose-overflow
Browse files Browse the repository at this point in the history
Avoid stack overflow when disposing batched sink
  • Loading branch information
wparad authored Apr 2, 2024
2 parents 3fe84c7 + eeb6a64 commit 700e588
Show file tree
Hide file tree
Showing 4 changed files with 419 additions and 400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Serilog.Formatting;
using Serilog.Formatting.Json;
using Serilog.Sinks.AwsCloudWatch.LogStreamNameProvider;
using Serilog.Sinks.PeriodicBatching;

namespace Serilog.Sinks.AwsCloudWatch
{
Expand Down Expand Up @@ -37,9 +38,16 @@ public static LoggerConfiguration AmazonCloudWatch(this LoggerSinkConfiguration
{
throw new ArgumentNullException(nameof(cloudWatchClient));
}

// the batched sink is
var batchedSink = new PeriodicBatchingSinkImplementationCallback(cloudWatchClient, options);

// create the sink
var sink = new CloudWatchLogSink(cloudWatchClient, options);
var sink = new PeriodicBatchingSink(batchedSink, new()
{
BatchSizeLimit = options.BatchSizeLimit,
Period = options.Period,
QueueLimit = options.QueueSizeLimit
});

// register the sink
return loggerConfiguration.Sink(sink, options.MinimumLogEventLevel);
Expand Down Expand Up @@ -180,10 +188,8 @@ public static LoggerConfiguration AmazonCloudWatch(
}

var client = cloudWatchClient ?? new AmazonCloudWatchLogsClient();

// Create and register the sink
var sink = new CloudWatchLogSink(client, options);
return loggerConfiguration.Sink(sink, options.MinimumLogEventLevel);

return AmazonCloudWatch(loggerConfiguration, options, client);
}
}
}
Loading

0 comments on commit 700e588

Please sign in to comment.