Skip to content

Commit

Permalink
Merge pull request #15 from skomis-mm/thread
Browse files Browse the repository at this point in the history
Remove System.Threading.Thread dependency; adds support for netstandard-1.1
  • Loading branch information
nblumhardt authored Feb 14, 2017
2 parents 0d4602f + 3a78689 commit 9212a73
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/Serilog.Sinks.Async/Sinks/Async/BackgroundWorkerSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Serilog.Core;
using Serilog.Debugging;
using Serilog.Events;
using System.Threading.Tasks;

namespace Serilog.Sinks.Async
{
Expand All @@ -14,7 +15,7 @@ sealed class BackgroundWorkerSink : ILogEventSink, IDisposable
volatile bool _disposed;
readonly CancellationTokenSource _cancel = new CancellationTokenSource();
readonly BlockingCollection<LogEvent> _queue;
readonly Thread _worker;
readonly Task _worker;

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

public void Emit(LogEvent logEvent)
Expand All @@ -39,7 +39,7 @@ public void Dispose()
{
_disposed = true;
_cancel.Cancel();
_worker.Join();
_worker.Wait();
_pipeline.Dispose();
// _cancel not disposed, because it will make _cancel.Cancel() non-idempotent
}
Expand Down
11 changes: 2 additions & 9 deletions src/Serilog.Sinks.Async/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,9 @@
"frameworks": {
"net4.5": {
},
"netstandard1.3": {
"netstandard1.1": {
"dependencies": {
"Microsoft.CSharp": "4.0.1",
"System.Collections": "4.0.11",
"System.Linq": "4.1.0",
"System.Runtime": "4.1.0",
"System.Runtime.Extensions": "4.1.0",
"System.Threading": "4.0.11",
"System.Collections.Concurrent": "4.0.12",
"System.Threading.Thread": "4.0.0"
"System.Collections.Concurrent": "4.0.12"
}
}
}
Expand Down

0 comments on commit 9212a73

Please sign in to comment.