Skip to content

Commit d4b3b32

Browse files
committed
Fix exception handling in BackgroundWorkerSink; resolves #44
1 parent 5ca49a1 commit d4b3b32

File tree

6 files changed

+38
-24
lines changed

6 files changed

+38
-24
lines changed

appveyor.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
version: '{build}'
22
skip_tags: true
33
image: Visual Studio 2017
4-
configuration: Release
54
build_script:
65
- ps: ./Build.ps1
76
test: off

serilog-sinks-async.sln.DotSettings

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Serilog/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
<PropertyGroup>
44
<Description>Asynchronous sink wrapper for Serilog.</Description>
5-
<AssemblyVersion>1.3.1.0</AssemblyVersion>
6-
<VersionPrefix>1.3.1</VersionPrefix>
5+
<AssemblyVersion>1.4.0.0</AssemblyVersion>
6+
<VersionPrefix>1.4.0</VersionPrefix>
77
<Authors>Jezz Santos;Serilog Contributors</Authors>
8-
<TargetFrameworks>net45;netstandard1.1</TargetFrameworks>
8+
<TargetFrameworks>net45;netstandard1.1;net461;netstandard2.0</TargetFrameworks>
99
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1111
<AssemblyName>Serilog.Sinks.Async</AssemblyName>
@@ -15,24 +15,24 @@
1515
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
1616
<PackageId>Serilog.Sinks.Async</PackageId>
1717
<PackageTags>serilog;async</PackageTags>
18-
<PackageIconUrl>http://serilog.net/images/serilog-sink-nuget.png</PackageIconUrl>
18+
<PackageIconUrl>https://serilog.net/images/serilog-sink-nuget.png</PackageIconUrl>
1919
<PackageProjectUrl>https://serilog.net</PackageProjectUrl>
2020
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
2121
<RepositoryUrl>https://github.com/serilog/serilog-sinks-async</RepositoryUrl>
2222
<RepositoryType>git</RepositoryType>
2323
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
2424
</PropertyGroup>
2525

26-
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
26+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' Or '$(TargetFramework)' == 'net461' ">
2727
<!-- Don't reference the full NETStandard.Library -->
2828
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
2929
</PropertyGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="Serilog" Version="2.7.1" />
32+
<PackageReference Include="Serilog" Version="2.8.0" />
3333
</ItemGroup>
3434

35-
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
35+
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' Or '$(TargetFramework)' == 'net461' ">
3636
<Reference Include="System" />
3737
<Reference Include="Microsoft.CSharp" />
3838
</ItemGroup>

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

+14-7
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ namespace Serilog.Sinks.Async
1010
{
1111
sealed class BackgroundWorkerSink : ILogEventSink, IAsyncLogEventSinkInspector, IDisposable
1212
{
13-
readonly ILogEventSink _pipeline;
13+
readonly ILogEventSink _wrappedSink;
1414
readonly bool _blockWhenFull;
1515
readonly BlockingCollection<LogEvent> _queue;
1616
readonly Task _worker;
1717
readonly IAsyncLogEventSinkMonitor _monitor;
1818

1919
long _droppedMessages;
2020

21-
public BackgroundWorkerSink(ILogEventSink pipeline, int bufferCapacity, bool blockWhenFull, IAsyncLogEventSinkMonitor monitor = null)
21+
public BackgroundWorkerSink(ILogEventSink wrappedSink, int bufferCapacity, bool blockWhenFull, IAsyncLogEventSinkMonitor monitor = null)
2222
{
2323
if (bufferCapacity <= 0) throw new ArgumentOutOfRangeException(nameof(bufferCapacity));
24-
_pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline));
24+
_wrappedSink = wrappedSink ?? throw new ArgumentNullException(nameof(wrappedSink));
2525
_blockWhenFull = blockWhenFull;
2626
_queue = new BlockingCollection<LogEvent>(bufferCapacity);
2727
_worker = Task.Factory.StartNew(Pump, CancellationToken.None, TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
@@ -64,7 +64,7 @@ public void Dispose()
6464
// Allow queued events to be flushed
6565
_worker.Wait();
6666

67-
(_pipeline as IDisposable)?.Dispose();
67+
(_wrappedSink as IDisposable)?.Dispose();
6868

6969
_monitor?.StopMonitoring(this);
7070
}
@@ -75,12 +75,19 @@ void Pump()
7575
{
7676
foreach (var next in _queue.GetConsumingEnumerable())
7777
{
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+
}
7986
}
8087
}
81-
catch (Exception ex)
88+
catch (Exception fatal)
8289
{
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);
8491
}
8592
}
8693

test/Serilog.Sinks.Async.PerformanceTests/Serilog.Sinks.Async.PerformanceTests.csproj

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net46;netcoreapp1.1</TargetFrameworks>
4+
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
55
<AssemblyName>Serilog.Sinks.Async.PerformanceTests</AssemblyName>
66
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
77
<SignAssembly>true</SignAssembly>
@@ -17,10 +17,13 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
21-
<PackageReference Include="xunit" Version="2.3.1" />
22-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
23-
<PackageReference Include="BenchmarkDotNet" Version="0.10.6" />
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
21+
<PackageReference Include="xunit" Version="2.4.1" />
22+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
23+
<PrivateAssets>all</PrivateAssets>
24+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
25+
</PackageReference>
26+
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
2427
<PackageReference Include="Serilog.Sinks.File" Version="3.1.0" />
2528
</ItemGroup>
2629

test/Serilog.Sinks.Async.Tests/Serilog.Sinks.Async.Tests.csproj

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net452;netcoreapp1.0</TargetFrameworks>
4+
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
55
<AssemblyName>Serilog.Sinks.Async.Tests</AssemblyName>
66
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
77
<SignAssembly>true</SignAssembly>
@@ -14,9 +14,12 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
18-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
19-
<PackageReference Include="xunit" Version="2.3.1" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
18+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
19+
<PrivateAssets>all</PrivateAssets>
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
21+
</PackageReference>
22+
<PackageReference Include="xunit" Version="2.4.1" />
2023
</ItemGroup>
2124

2225
<ItemGroup>

0 commit comments

Comments
 (0)