Skip to content

Commit

Permalink
Serilog.Sinks.Postgresql.Alternative: Fixed Serilog sink after migrat…
Browse files Browse the repository at this point in the history
…ion to V4 (Batching).
  • Loading branch information
SeppPenner committed Jul 2, 2024
1 parent 9a23a5c commit dd282cd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/Serilog.Sinks.Postgresql.Alternative/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
global using Serilog.Debugging;
global using Serilog.Events;
global using Serilog.Formatting.Json;
global using Serilog.Sinks.PeriodicBatching;
global using Serilog.Sinks.PostgreSQL;
global using Serilog.Sinks.PostgreSQL.ColumnWriters;
global using Serilog.Sinks.PostgreSQL.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,14 @@ public static LoggerConfiguration PostgreSQL(
onCreateTableCallback,
onCreateSchemaCallback);

var batchingOptions = new PeriodicBatchingSinkOptions()
var batchingOptions = new BatchingOptions()
{
BatchSizeLimit = optionsLocal.BatchSizeLimit,
Period = optionsLocal.Period,
BufferingTimeLimit = optionsLocal.Period,
QueueLimit = optionsLocal.QueueLimit
};

var batchingSink = new PeriodicBatchingSink(new PostgreSqlSink(optionsLocal), batchingOptions);
return sinkConfiguration.Sink(batchingSink, restrictedToMinimumLevel, levelSwitch);
return sinkConfiguration.Sink(new PostgreSqlSink(optionsLocal), batchingOptions, restrictedToMinimumLevel, levelSwitch);
}

/// <summary>
Expand Down Expand Up @@ -238,15 +237,14 @@ public static LoggerConfiguration PostgreSQL(
onCreateTableCallback,
onCreateSchemaCallback);

var batchingOptions = new PeriodicBatchingSinkOptions()
var batchingOptions = new BatchingOptions()
{
BatchSizeLimit = optionsLocal.BatchSizeLimit,
Period = optionsLocal.Period,
BufferingTimeLimit = optionsLocal.Period,
QueueLimit = optionsLocal.QueueLimit
};

var batchingSink = new PeriodicBatchingSink(new PostgreSqlSink(optionsLocal), batchingOptions);
return sinkConfiguration.Sink(batchingSink, restrictedToMinimumLevel, levelSwitch);
return sinkConfiguration.Sink(new PostgreSqlSink(optionsLocal), batchingOptions, restrictedToMinimumLevel, levelSwitch);
}

columns ??= new Dictionary<string, ColumnWriterBase>();
Expand All @@ -272,15 +270,14 @@ public static LoggerConfiguration PostgreSQL(
onCreateTableCallback,
onCreateSchemaCallback);

var batchingOptions2 = new PeriodicBatchingSinkOptions()
var batchingOptions2 = new BatchingOptions()
{
BatchSizeLimit = optionsLocal2.BatchSizeLimit,
Period = optionsLocal2.Period,
BufferingTimeLimit = optionsLocal2.Period,
QueueLimit = optionsLocal2.QueueLimit
};

var batchingSink2 = new PeriodicBatchingSink(new PostgreSqlSink(optionsLocal2), batchingOptions2);
return sinkConfiguration.Sink(batchingSink2, restrictedToMinimumLevel, levelSwitch);
return sinkConfiguration.Sink(new PostgreSqlSink(optionsLocal2), batchingOptions2, restrictedToMinimumLevel, levelSwitch);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class PostgreSqlAuditSink : ILogEventSink, IDisposable
/// </summary>
private readonly SinkHelper sinkHelper;

/// <inheritdoc cref="PeriodicBatchingSink" />
/// <summary>
/// Initializes a new instance of the <see cref="PostgreSqlSink" /> class.
/// </summary>
Expand All @@ -39,7 +38,7 @@ public PostgreSqlAuditSink(PostgreSqlOptions options)
/// <param name="logEvent"> a log event to emit </param>
public async void Emit(LogEvent logEvent)
{
await this.sinkHelper.Emit(new List<LogEvent> { logEvent });
await this.sinkHelper.Emit([logEvent]);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public PostgreSqlSink(PostgreSqlOptions options)
/// <returns></returns>
/// <exception cref="LoggingFailedException">Received failed result {result.StatusCode} when posting events to Microsoft Teams</exception>
/// <remarks>
/// Override either <see cref="M:Serilog.Sinks.PeriodicBatching.IBatchedLogEventSink.EmitBatch(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" /> or <see cref="M:Serilog.Sinks.PeriodicBatching.IBatchedLogEventSink.EmitBatchAsync(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" />,
/// Override either <see cref="M:Serilog.Sinks.PeriodicBatching.IBatchedLogEventSink.EmitBatch(System.Collections.Generic.IReadOnlyCollection{Serilog.Events.LogEvent})" /> or <see cref="M:Serilog.Sinks.PeriodicBatching.IBatchedLogEventSink.EmitBatchAsync(System.Collections.Generic.IReadOnlyCollection{Serilog.Events.LogEvent})" />,
/// not both. Overriding EmitBatch() is preferred.
/// </remarks>
public async Task EmitBatchAsync(IEnumerable<LogEvent> events)
public async Task EmitBatchAsync(IReadOnlyCollection<LogEvent> events)
{
try
{
Expand Down

0 comments on commit dd282cd

Please sign in to comment.