@@ -10,18 +10,18 @@ namespace Serilog.Sinks.Async
10
10
{
11
11
sealed class BackgroundWorkerSink : ILogEventSink , IAsyncLogEventSinkInspector , IDisposable
12
12
{
13
- readonly ILogEventSink _pipeline ;
13
+ readonly ILogEventSink _wrappedSink ;
14
14
readonly bool _blockWhenFull ;
15
15
readonly BlockingCollection < LogEvent > _queue ;
16
16
readonly Task _worker ;
17
17
readonly IAsyncLogEventSinkMonitor _monitor ;
18
18
19
19
long _droppedMessages ;
20
20
21
- public BackgroundWorkerSink ( ILogEventSink pipeline , int bufferCapacity , bool blockWhenFull , IAsyncLogEventSinkMonitor monitor = null )
21
+ public BackgroundWorkerSink ( ILogEventSink wrappedSink , int bufferCapacity , bool blockWhenFull , IAsyncLogEventSinkMonitor monitor = null )
22
22
{
23
23
if ( bufferCapacity <= 0 ) throw new ArgumentOutOfRangeException ( nameof ( bufferCapacity ) ) ;
24
- _pipeline = pipeline ?? throw new ArgumentNullException ( nameof ( pipeline ) ) ;
24
+ _wrappedSink = wrappedSink ?? throw new ArgumentNullException ( nameof ( wrappedSink ) ) ;
25
25
_blockWhenFull = blockWhenFull ;
26
26
_queue = new BlockingCollection < LogEvent > ( bufferCapacity ) ;
27
27
_worker = Task . Factory . StartNew ( Pump , CancellationToken . None , TaskCreationOptions . LongRunning | TaskCreationOptions . DenyChildAttach , TaskScheduler . Default ) ;
@@ -64,7 +64,7 @@ public void Dispose()
64
64
// Allow queued events to be flushed
65
65
_worker . Wait ( ) ;
66
66
67
- ( _pipeline as IDisposable ) ? . Dispose ( ) ;
67
+ ( _wrappedSink as IDisposable ) ? . Dispose ( ) ;
68
68
69
69
_monitor ? . StopMonitoring ( this ) ;
70
70
}
@@ -75,12 +75,19 @@ void Pump()
75
75
{
76
76
foreach ( var next in _queue . GetConsumingEnumerable ( ) )
77
77
{
78
- _pipeline . Emit ( next ) ;
78
+ try
79
+ {
80
+ _wrappedSink . Emit ( next ) ;
81
+ }
82
+ catch ( Exception ex )
83
+ {
84
+ SelfLog . WriteLine ( "{0} failed to emit event to wrapped sink: {1}" , typeof ( BackgroundWorkerSink ) , ex ) ;
85
+ }
79
86
}
80
87
}
81
- catch ( Exception ex )
88
+ catch ( Exception fatal )
82
89
{
83
- SelfLog . WriteLine ( "{0} fatal error in worker thread: {1}" , typeof ( BackgroundWorkerSink ) , ex ) ;
90
+ SelfLog . WriteLine ( "{0} fatal error in worker thread: {1}" , typeof ( BackgroundWorkerSink ) , fatal ) ;
84
91
}
85
92
}
86
93
0 commit comments