Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove System.Threading.Thread dependency #15

Merged
merged 1 commit into from
Feb 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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