Skip to content

Commit 9212a73

Browse files
authored
Merge pull request #15 from skomis-mm/thread
Remove System.Threading.Thread dependency; adds support for netstandard-1.1
2 parents 0d4602f + 3a78689 commit 9212a73

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Serilog.Core;
55
using Serilog.Debugging;
66
using Serilog.Events;
7+
using System.Threading.Tasks;
78

89
namespace Serilog.Sinks.Async
910
{
@@ -14,7 +15,7 @@ sealed class BackgroundWorkerSink : ILogEventSink, IDisposable
1415
volatile bool _disposed;
1516
readonly CancellationTokenSource _cancel = new CancellationTokenSource();
1617
readonly BlockingCollection<LogEvent> _queue;
17-
readonly Thread _worker;
18+
readonly Task _worker;
1819

1920
public BackgroundWorkerSink(Logger pipeline, int bufferCapacity)
2021
{
@@ -23,8 +24,7 @@ public BackgroundWorkerSink(Logger pipeline, int bufferCapacity)
2324
_pipeline = pipeline;
2425
_bufferCapacity = bufferCapacity;
2526
_queue = new BlockingCollection<LogEvent>(_bufferCapacity);
26-
_worker = new Thread(Pump) { IsBackground = true, Name = typeof(BackgroundWorkerSink).FullName };
27-
_worker.Start();
27+
_worker = Task.Factory.StartNew(Pump, CancellationToken.None, TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
2828
}
2929

3030
public void Emit(LogEvent logEvent)
@@ -39,7 +39,7 @@ public void Dispose()
3939
{
4040
_disposed = true;
4141
_cancel.Cancel();
42-
_worker.Join();
42+
_worker.Wait();
4343
_pipeline.Dispose();
4444
// _cancel not disposed, because it will make _cancel.Cancel() non-idempotent
4545
}

src/Serilog.Sinks.Async/project.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,9 @@
2424
"frameworks": {
2525
"net4.5": {
2626
},
27-
"netstandard1.3": {
27+
"netstandard1.1": {
2828
"dependencies": {
29-
"Microsoft.CSharp": "4.0.1",
30-
"System.Collections": "4.0.11",
31-
"System.Linq": "4.1.0",
32-
"System.Runtime": "4.1.0",
33-
"System.Runtime.Extensions": "4.1.0",
34-
"System.Threading": "4.0.11",
35-
"System.Collections.Concurrent": "4.0.12",
36-
"System.Threading.Thread": "4.0.0"
29+
"System.Collections.Concurrent": "4.0.12"
3730
}
3831
}
3932
}

0 commit comments

Comments
 (0)