Skip to content

Commit 67cfc0e

Browse files
author
Sergey Komisarchik
committed
make use of lightweight LoggingSinkConfiguration.Wrap(..)
1 parent 4ed2d2d commit 67cfc0e

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

src/Serilog.Sinks.Async/LoggerConfigurationAsyncExtensions.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using Serilog.Configuration;
3-
using Serilog.Events;
3+
44
using Serilog.Sinks.Async;
55

66
namespace Serilog
@@ -24,14 +24,10 @@ public static LoggerConfiguration Async(
2424
Action<LoggerSinkConfiguration> configure,
2525
int bufferSize = 10000)
2626
{
27-
var sublogger = new LoggerConfiguration();
28-
sublogger.MinimumLevel.Is(LevelAlias.Minimum);
29-
30-
configure(sublogger.WriteTo);
31-
32-
var wrapper = new BackgroundWorkerSink(sublogger.CreateLogger(), bufferSize);
33-
34-
return loggerSinkConfiguration.Sink(wrapper);
27+
return LoggerSinkConfiguration.Wrap(
28+
loggerSinkConfiguration,
29+
wrappedSink => new BackgroundWorkerSink(wrappedSink, bufferSize),
30+
configure);
3531
}
3632
}
3733
}

src/Serilog.Sinks.Async/Serilog.Sinks.Async.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<PackageReference Include="Serilog" Version="2.1.0" />
26+
<PackageReference Include="Serilog" Version="2.5.0" />
2727
</ItemGroup>
2828

2929
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">

src/Serilog.Sinks.Async/Sinks/Async/BackgroundWorkerSink.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ namespace Serilog.Sinks.Async
1010
{
1111
sealed class BackgroundWorkerSink : ILogEventSink, IDisposable
1212
{
13-
readonly Logger _pipeline;
13+
readonly ILogEventSink _pipeline;
1414
readonly int _bufferCapacity;
1515
volatile bool _disposed;
1616
readonly CancellationTokenSource _cancel = new CancellationTokenSource();
1717
readonly BlockingCollection<LogEvent> _queue;
1818
readonly Task _worker;
1919

20-
public BackgroundWorkerSink(Logger pipeline, int bufferCapacity)
20+
public BackgroundWorkerSink(ILogEventSink pipeline, int bufferCapacity)
2121
{
2222
if (pipeline == null) throw new ArgumentNullException(nameof(pipeline));
2323
if (bufferCapacity <= 0) throw new ArgumentOutOfRangeException(nameof(bufferCapacity));
@@ -40,7 +40,7 @@ public void Dispose()
4040
_disposed = true;
4141
_cancel.Cancel();
4242
_worker.Wait();
43-
_pipeline.Dispose();
43+
(_pipeline as IDisposable)?.Dispose();
4444
// _cancel not disposed, because it will make _cancel.Cancel() non-idempotent
4545
}
4646

@@ -53,14 +53,14 @@ void Pump()
5353
while (true)
5454
{
5555
var next = _queue.Take(_cancel.Token);
56-
_pipeline.Write(next);
56+
_pipeline.Emit(next);
5757
}
5858
}
5959
catch (OperationCanceledException)
6060
{
6161
LogEvent next;
6262
while (_queue.TryTake(out next))
63-
_pipeline.Write(next);
63+
_pipeline.Emit(next);
6464
}
6565
}
6666
catch (Exception ex)

0 commit comments

Comments
 (0)