Skip to content

Commit 7f92f72

Browse files
committed
update to Serilog 4.0, remove writeInBatches, remove Serilog.Sinks.PeriodicBatching
1 parent a5501fa commit 7f92f72

File tree

5 files changed

+103
-119
lines changed

5 files changed

+103
-119
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ public static class Program
160160

161161
### Change Log
162162

163+
10.0.0
164+
* Breaking: writeInBatches removed, all writes are now batched
165+
* Update: update to serilog 4.0
166+
* Remove: removed dependance on Serilog.Sinks.PeriodicBatching, use serilog 4.0 `IBatchedLogEventSink`
167+
168+
9.6.0
169+
* Fix: improve timezone support
170+
171+
9.5.0
172+
* Add: use ULID for rowkey for speed and efficiency
173+
174+
9.4.0
175+
* Fix: prevent duplicate rowkey
176+
163177
9.1.0
164178
* Add: Built-in trace and span id support
165179

src/Serilog.Sinks.AzureTableStorage/LoggerConfigurationAzureTableStorageExtensions.cs

+9-36
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
using Serilog.Formatting;
2626
using Serilog.Formatting.Json;
2727
using Serilog.Sinks.AzureTableStorage;
28-
using Serilog.Sinks.PeriodicBatching;
2928

3029
namespace Serilog;
3130

@@ -53,7 +52,6 @@ public static class LoggerConfigurationAzureTableStorageExtensions
5352
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
5453
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
5554
/// <param name="storageTableName">Table name that log entries will be written to. Note: Optional, setting this may impact performance</param>
56-
/// <param name="writeInBatches">Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink</param>
5755
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
5856
/// <param name="period">The time to wait between checking for event batches.</param>
5957
/// <param name="keyGenerator">The key generator used to create the PartitionKey and the RowKey for each log entry</param>
@@ -70,7 +68,6 @@ public static LoggerConfiguration AzureTableStorage(
7068
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
7169
IFormatProvider formatProvider = null,
7270
string storageTableName = null,
73-
bool writeInBatches = true,
7471
TimeSpan? period = null,
7572
int? batchPostingLimit = null,
7673
IKeyGenerator keyGenerator = null,
@@ -92,7 +89,6 @@ public static LoggerConfiguration AzureTableStorage(
9289
restrictedToMinimumLevel: restrictedToMinimumLevel,
9390
formatProvider: formatProvider,
9491
storageTableName: storageTableName,
95-
writeInBatches: writeInBatches,
9692
period: period,
9793
batchPostingLimit: batchPostingLimit,
9894
keyGenerator: keyGenerator,
@@ -111,7 +107,6 @@ public static LoggerConfiguration AzureTableStorage(
111107
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
112108
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
113109
/// <param name="storageTableName">Table name that log entries will be written to. Note: Optional, setting this may impact performance</param>
114-
/// <param name="writeInBatches">Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink</param>
115110
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
116111
/// <param name="period">The time to wait between checking for event batches.</param>
117112
/// <param name="keyGenerator">The key generator used to create the PartitionKey and the RowKey for each log entry</param>
@@ -128,7 +123,6 @@ public static LoggerConfiguration AzureTableStorage(
128123
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
129124
IFormatProvider formatProvider = null,
130125
string storageTableName = null,
131-
bool writeInBatches = true,
132126
TimeSpan? period = null,
133127
int? batchPostingLimit = null,
134128
IKeyGenerator keyGenerator = null,
@@ -150,7 +144,6 @@ public static LoggerConfiguration AzureTableStorage(
150144
restrictedToMinimumLevel: restrictedToMinimumLevel,
151145
formatProvider: formatProvider,
152146
storageTableName: storageTableName,
153-
writeInBatches: writeInBatches,
154147
period: period,
155148
batchPostingLimit: batchPostingLimit,
156149
keyGenerator: keyGenerator,
@@ -171,7 +164,6 @@ public static LoggerConfiguration AzureTableStorage(
171164
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
172165
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
173166
/// <param name="storageTableName">Table name that log entries will be written to. Note: Optional, setting this may impact performance</param>
174-
/// <param name="writeInBatches">Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink</param>
175167
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
176168
/// <param name="period">The time to wait between checking for event batches.</param>
177169
/// <param name="keyGenerator">The key generator used to create the PartitionKey and the RowKey for each log entry</param>
@@ -189,7 +181,6 @@ public static LoggerConfiguration AzureTableStorage(
189181
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
190182
IFormatProvider formatProvider = null,
191183
string storageTableName = null,
192-
bool writeInBatches = true,
193184
TimeSpan? period = null,
194185
int? batchPostingLimit = null,
195186
IKeyGenerator keyGenerator = null,
@@ -214,7 +205,6 @@ public static LoggerConfiguration AzureTableStorage(
214205
restrictedToMinimumLevel: restrictedToMinimumLevel,
215206
formatProvider: formatProvider,
216207
storageTableName: storageTableName,
217-
writeInBatches: writeInBatches,
218208
period: period,
219209
batchPostingLimit: batchPostingLimit,
220210
keyGenerator: keyGenerator,
@@ -233,7 +223,6 @@ public static LoggerConfiguration AzureTableStorage(
233223
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
234224
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
235225
/// <param name="storageTableName">Table name that log entries will be written to. Note: Optional, setting this may impact performance</param>
236-
/// <param name="writeInBatches">Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink;</param>
237226
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
238227
/// <param name="period">The time to wait between checking for event batches.</param>
239228
/// <param name="keyGenerator">The key generator used to create the PartitionKey and the RowKey for each log entry</param>
@@ -251,7 +240,6 @@ public static LoggerConfiguration AzureTableStorage(
251240
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
252241
IFormatProvider formatProvider = null,
253242
string storageTableName = null,
254-
bool writeInBatches = true,
255243
TimeSpan? period = null,
256244
int? batchPostingLimit = null,
257245
IKeyGenerator keyGenerator = null,
@@ -268,7 +256,6 @@ public static LoggerConfiguration AzureTableStorage(
268256
if (storageAccount == null)
269257
throw new ArgumentNullException(nameof(storageAccount));
270258

271-
ILogEventSink sink;
272259
try
273260
{
274261
var options = new AzureTableStorageSinkOptions
@@ -292,30 +279,22 @@ public static LoggerConfiguration AzureTableStorage(
292279
keyGenerator: keyGenerator,
293280
tableClientFactory: tableClientFactory);
294281

295-
if (writeInBatches)
282+
var batchingOptions = new BatchingOptions
296283
{
297-
// wrap in PeriodicBatchingSink
298-
var batchingOptions = new PeriodicBatchingSinkOptions
299-
{
300-
BatchSizeLimit = batchPostingLimit ?? DefaultBatchSizeLimit,
301-
EagerlyEmitFirstEvent = true,
302-
Period = period ?? DefaultPeriod,
303-
};
304-
305-
sink = new PeriodicBatchingSink(tableStorageSink, batchingOptions);
306-
}
307-
else
308-
{
309-
sink = tableStorageSink;
310-
}
284+
BatchSizeLimit = batchPostingLimit ?? DefaultBatchSizeLimit,
285+
EagerlyEmitFirstEvent = true,
286+
BufferingTimeLimit = period ?? DefaultPeriod,
287+
};
288+
289+
return loggerConfiguration.Sink(tableStorageSink, batchingOptions, restrictedToMinimumLevel);
311290
}
312291
catch (Exception ex)
313292
{
314293
Debugging.SelfLog.WriteLine($"Error configuring AzureTableStorage: {ex}");
315-
sink = new LoggerConfiguration().CreateLogger();
294+
var sink = new LoggerConfiguration().CreateLogger();
295+
return loggerConfiguration.Sink(sink);
316296
}
317297

318-
return loggerConfiguration.Sink(sink, restrictedToMinimumLevel);
319298
}
320299

321300
/// <summary>
@@ -327,7 +306,6 @@ public static LoggerConfiguration AzureTableStorage(
327306
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
328307
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
329308
/// <param name="storageTableName">Table name that log entries will be written to. Note: Optional, setting this may impact performance</param>
330-
/// <param name="writeInBatches">Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink</param>
331309
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
332310
/// <param name="period">The time to wait between checking for event batches.</param>
333311
/// <param name="keyGenerator">The key generator used to create the PartitionKey and the RowKey for each log entry</param>
@@ -345,7 +323,6 @@ public static LoggerConfiguration AzureTableStorage(
345323
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
346324
IFormatProvider formatProvider = null,
347325
string storageTableName = null,
348-
bool writeInBatches = true,
349326
TimeSpan? period = null,
350327
int? batchPostingLimit = null,
351328
IKeyGenerator keyGenerator = null,
@@ -373,7 +350,6 @@ public static LoggerConfiguration AzureTableStorage(
373350
restrictedToMinimumLevel: restrictedToMinimumLevel,
374351
formatProvider: formatProvider,
375352
storageTableName: storageTableName,
376-
writeInBatches: writeInBatches,
377353
period: period,
378354
batchPostingLimit: batchPostingLimit,
379355
keyGenerator: keyGenerator,
@@ -404,7 +380,6 @@ public static LoggerConfiguration AzureTableStorage(
404380
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
405381
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
406382
/// <param name="storageTableName">Table name that log entries will be written to. Note: Optional, setting this may impact performance</param>
407-
/// <param name="writeInBatches">Use a periodic batching sink, as opposed to a synchronous one-at-a-time sink</param>
408383
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
409384
/// <param name="period">The time to wait between checking for event batches.</param>
410385
/// <param name="keyGenerator">The key generator used to create the PartitionKey and the RowKey for each log entry</param>
@@ -423,7 +398,6 @@ public static LoggerConfiguration AzureTableStorage(
423398
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
424399
IFormatProvider formatProvider = null,
425400
string storageTableName = null,
426-
bool writeInBatches = true,
427401
TimeSpan? period = null,
428402
int? batchPostingLimit = null,
429403
IKeyGenerator keyGenerator = null,
@@ -460,7 +434,6 @@ public static LoggerConfiguration AzureTableStorage(
460434
restrictedToMinimumLevel: restrictedToMinimumLevel,
461435
formatProvider: formatProvider,
462436
storageTableName: storageTableName,
463-
writeInBatches: writeInBatches,
464437
period: period,
465438
batchPostingLimit: batchPostingLimit,
466439
keyGenerator: keyGenerator,

src/Serilog.Sinks.AzureTableStorage/Serilog.Sinks.AzureTableStorage.csproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353

5454
<ItemGroup>
5555
<PackageReference Include="MinVer" Version="5.0.0" PrivateAssets="All" />
56-
<PackageReference Include="Serilog" Version="3.1.1" />
57-
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="4.1.1" />
56+
<PackageReference Include="Serilog" Version="4.0.0" />
5857
<PackageReference Include="Azure.Data.Tables" Version="12.8.3" />
5958
<PackageReference Include="ulid" Version="1.3.3" />
6059
</ItemGroup>

src/Serilog.Sinks.AzureTableStorage/Sinks/AzureTableStorage/AzureTableStorageSink.cs

+3-20
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121

2222
using Serilog.Core;
2323
using Serilog.Events;
24-
using Serilog.Sinks.PeriodicBatching;
2524

2625
namespace Serilog.Sinks.AzureTableStorage;
2726

2827
/// <summary>
2928
/// Writes log events as records to an Azure Table Storage table.
3029
/// </summary>
31-
public class AzureTableStorageSink : ILogEventSink, IBatchedLogEventSink
30+
public class AzureTableStorageSink : IBatchedLogEventSink
3231
{
3332
private readonly TableServiceClient _tableServiceClient;
3433
private readonly AzureTableStorageSinkOptions _options;
@@ -71,25 +70,12 @@ public AzureTableStorageSink(
7170
_tableClientFactory = tableClientFactory ?? new DefaultTableClientFactory();
7271
}
7372

74-
/// <summary>
75-
/// Emit the provided log event to the sink.
76-
/// </summary>
77-
/// <param name="logEvent">The log event to write.</param>
78-
/// <exception cref="System.NotImplementedException"></exception>
79-
public void Emit(LogEvent logEvent)
80-
{
81-
var document = _documentFactory.Create(logEvent, _options, _keyGenerator);
82-
var tableClient = _tableClientFactory.CreateTableClient(_options, _tableServiceClient);
83-
84-
tableClient.AddEntity(document);
85-
}
86-
8773
/// <summary>
8874
/// Emit a batch of log events, running asynchronously.
8975
/// </summary>
9076
/// <param name="batch">The batch of events to emit.</param>
9177
/// <returns></returns>
92-
public async Task EmitBatchAsync(IEnumerable<LogEvent> batch)
78+
public async Task EmitBatchAsync(IReadOnlyCollection<LogEvent> batch)
9379
{
9480
// write documents in batches by partition key
9581
var documentGroups = batch
@@ -116,8 +102,5 @@ public async Task EmitBatchAsync(IEnumerable<LogEvent> batch)
116102
/// or timers (thus avoiding additional flush/shut-down complexity).
117103
/// </summary>
118104
/// <returns></returns>
119-
public Task OnEmptyBatchAsync()
120-
{
121-
return Task.CompletedTask;
122-
}
105+
public Task OnEmptyBatchAsync() => Task.CompletedTask;
123106
}

0 commit comments

Comments
 (0)