Skip to content

Commit e01d84d

Browse files
authored
Merge pull request #19 from skomis-mm/wrap
Simplify wrapping configuration using new LoggerSinkConfiguration.Wrap(..) method
2 parents fc636e8 + 67cfc0e commit e01d84d

18 files changed

+131
-196
lines changed

Bench.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ foreach ($test in ls test/*.PerformanceTests) {
99

1010
echo "bench: Benchmarking project in $test"
1111

12-
& dotnet test -c Release --framework net4.5.2
12+
& dotnet test -c Release --framework net46
1313
if($LASTEXITCODE -ne 0) { exit 3 }
1414

1515
Pop-Location

Build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ foreach ($src in ls src/*) {
2020

2121
echo "build: Packaging project in $src"
2222

23-
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
23+
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix --include-source
2424
if($LASTEXITCODE -ne 0) { exit 1 }
2525

2626
Pop-Location

appveyor.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
version: '{build}'
22
skip_tags: true
3-
image: Visual Studio 2015
3+
image: Visual Studio 2017
44
configuration: Release
5-
install:
6-
- ps: mkdir -Force ".\build\" | Out-Null
7-
- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
8-
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli"
9-
- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.0-preview2-003121'
10-
- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
115
build_script:
126
- ps: ./Build.ps1
137
test: off

global.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

serilog-sinks-async.sln

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
2+
# Visual Studio 15
3+
VisualStudioVersion = 15.0.26430.14
54
MinimumVisualStudioVersion = 10.0.40219.1
65
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{76C9F320-3DBC-4613-83AA-3CCD0D9012D9}"
76
EndProject
@@ -12,42 +11,41 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{154C7C
1211
appveyor.yml = appveyor.yml
1312
Bench.ps1 = Bench.ps1
1413
Build.ps1 = Build.ps1
15-
global.json = global.json
1614
LICENSE = LICENSE
1715
README.md = README.md
1816
EndProjectSection
1917
EndProject
20-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Async", "src\Serilog.Sinks.Async\Serilog.Sinks.Async.xproj", "{803CD13A-D54B-4CEC-A55F-E22AE3D93B3C}"
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Sinks.Async", "src\Serilog.Sinks.Async\Serilog.Sinks.Async.csproj", "{003F6AB2-79F8-4A63-B501-5C564B4A4655}"
2119
EndProject
22-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Async.Tests", "test\Serilog.Sinks.Async.Tests\Serilog.Sinks.Async.Tests.xproj", "{3C2D8E01-5580-426A-BDD9-EC59CD98E618}"
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Sinks.Async.PerformanceTests", "test\Serilog.Sinks.Async.PerformanceTests\Serilog.Sinks.Async.PerformanceTests.csproj", "{19E64565-3BE1-43FE-9E8B-7800C7061877}"
2321
EndProject
24-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Async.PerformanceTests", "test\Serilog.Sinks.Async.PerformanceTests\Serilog.Sinks.Async.PerformanceTests.xproj", "{D7A37F73-BBA3-4DAE-9648-1A753A86F968}"
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Sinks.Async.Tests", "test\Serilog.Sinks.Async.Tests\Serilog.Sinks.Async.Tests.csproj", "{E8AE4DDD-6C28-4239-A752-075309A86D41}"
2523
EndProject
2624
Global
2725
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2826
Debug|Any CPU = Debug|Any CPU
2927
Release|Any CPU = Release|Any CPU
3028
EndGlobalSection
3129
GlobalSection(ProjectConfigurationPlatforms) = postSolution
32-
{803CD13A-D54B-4CEC-A55F-E22AE3D93B3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33-
{803CD13A-D54B-4CEC-A55F-E22AE3D93B3C}.Debug|Any CPU.Build.0 = Debug|Any CPU
34-
{803CD13A-D54B-4CEC-A55F-E22AE3D93B3C}.Release|Any CPU.ActiveCfg = Release|Any CPU
35-
{803CD13A-D54B-4CEC-A55F-E22AE3D93B3C}.Release|Any CPU.Build.0 = Release|Any CPU
36-
{3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37-
{3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.Build.0 = Debug|Any CPU
38-
{3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.ActiveCfg = Release|Any CPU
39-
{3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.Build.0 = Release|Any CPU
40-
{D7A37F73-BBA3-4DAE-9648-1A753A86F968}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41-
{D7A37F73-BBA3-4DAE-9648-1A753A86F968}.Debug|Any CPU.Build.0 = Debug|Any CPU
42-
{D7A37F73-BBA3-4DAE-9648-1A753A86F968}.Release|Any CPU.ActiveCfg = Release|Any CPU
43-
{D7A37F73-BBA3-4DAE-9648-1A753A86F968}.Release|Any CPU.Build.0 = Release|Any CPU
30+
{003F6AB2-79F8-4A63-B501-5C564B4A4655}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31+
{003F6AB2-79F8-4A63-B501-5C564B4A4655}.Debug|Any CPU.Build.0 = Debug|Any CPU
32+
{003F6AB2-79F8-4A63-B501-5C564B4A4655}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{003F6AB2-79F8-4A63-B501-5C564B4A4655}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{19E64565-3BE1-43FE-9E8B-7800C7061877}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{19E64565-3BE1-43FE-9E8B-7800C7061877}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{19E64565-3BE1-43FE-9E8B-7800C7061877}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{19E64565-3BE1-43FE-9E8B-7800C7061877}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{E8AE4DDD-6C28-4239-A752-075309A86D41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{E8AE4DDD-6C28-4239-A752-075309A86D41}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{E8AE4DDD-6C28-4239-A752-075309A86D41}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{E8AE4DDD-6C28-4239-A752-075309A86D41}.Release|Any CPU.Build.0 = Release|Any CPU
4442
EndGlobalSection
4543
GlobalSection(SolutionProperties) = preSolution
4644
HideSolutionNode = FALSE
4745
EndGlobalSection
4846
GlobalSection(NestedProjects) = preSolution
49-
{803CD13A-D54B-4CEC-A55F-E22AE3D93B3C} = {76C9F320-3DBC-4613-83AA-3CCD0D9012D9}
50-
{3C2D8E01-5580-426A-BDD9-EC59CD98E618} = {C36755AA-CED6-482B-B7B1-AE483BC3D273}
51-
{D7A37F73-BBA3-4DAE-9648-1A753A86F968} = {C36755AA-CED6-482B-B7B1-AE483BC3D273}
47+
{003F6AB2-79F8-4A63-B501-5C564B4A4655} = {76C9F320-3DBC-4613-83AA-3CCD0D9012D9}
48+
{19E64565-3BE1-43FE-9E8B-7800C7061877} = {C36755AA-CED6-482B-B7B1-AE483BC3D273}
49+
{E8AE4DDD-6C28-4239-A752-075309A86D41} = {C36755AA-CED6-482B-B7B1-AE483BC3D273}
5250
EndGlobalSection
5351
EndGlobal

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/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Reflection;
33
using System.Runtime.CompilerServices;
44

5-
[assembly: AssemblyVersion("1.0.0.0")]
65
[assembly: CLSCompliant(true)]
76
[assembly: InternalsVisibleTo("Serilog.Sinks.Async.Tests, PublicKey=" +
87
"0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" +
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Description>Asynchronous sink wrapper for Serilog.</Description>
5+
<AssemblyVersion>1.0.0</AssemblyVersion>
6+
<VersionPrefix>1.1.1</VersionPrefix>
7+
<Authors>Jezz Santos;Serilog Contributors</Authors>
8+
<TargetFrameworks>net45;netstandard1.1</TargetFrameworks>
9+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
10+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
11+
<AssemblyName>Serilog.Sinks.Async</AssemblyName>
12+
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
13+
<SignAssembly>true</SignAssembly>
14+
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
15+
<PackageId>Serilog.Sinks.Async</PackageId>
16+
<PackageTags>serilog;async</PackageTags>
17+
<PackageIconUrl>http://serilog.net/images/serilog-sink-nuget.png</PackageIconUrl>
18+
<PackageProjectUrl>https://serilog.net</PackageProjectUrl>
19+
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
20+
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
21+
<!-- Don't reference the full NETStandard.Library -->
22+
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
23+
</PropertyGroup>
24+
25+
<ItemGroup>
26+
<PackageReference Include="Serilog" Version="2.5.0" />
27+
</ItemGroup>
28+
29+
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
30+
<Reference Include="System" />
31+
<Reference Include="Microsoft.CSharp" />
32+
</ItemGroup>
33+
34+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' ">
35+
<PackageReference Include="System.Collections.Concurrent" Version="4.0.12" />
36+
</ItemGroup>
37+
38+
</Project>

src/Serilog.Sinks.Async/Serilog.Sinks.Async.xproj

Lines changed: 0 additions & 17 deletions
This file was deleted.

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)