diff --git a/README.md b/README.md index 3683188..b8b1d31 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Serilog.Sinks.Async [![Build status](https://ci.appveyor.com/api/projects/status/gvk0wl7aows14spn?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-async) [![NuGet](https://img.shields.io/nuget/vpre/Serilog.Sinks.Async.svg?maxAge=2592000)](https://www.nuget.org/packages/Serilog.Sinks.Async) [![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog) +# Serilog.Sinks.Async [![Build status](https://ci.appveyor.com/api/projects/status/gvk0wl7aows14spn?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-async) [![NuGet](https://img.shields.io/nuget/v/Serilog.Sinks.Async.svg)](https://www.nuget.org/packages/Serilog.Sinks.Async) [![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog) An asynchronous wrapper for other [Serilog](https://serilog.net) sinks. Use this sink to reduce the overhead of logging calls by delegating work to a background thread. This is especially suited to non-batching sinks like the [File](https://github.com/serilog/serilog-sinks-file) and [RollingFile](https://github.com/serilog-serilog-sinks-rollingfile) sinks that may be affected by I/O bottlenecks. @@ -9,7 +9,7 @@ An asynchronous wrapper for other [Serilog](https://serilog.net) sinks. Use this Install from [NuGet](https://nuget.org/packages/serilog.sinks.async): ```powershell -Install-Package Serilog.Sinks.Async -Pre +Install-Package Serilog.Sinks.Async ``` Assuming you have already installed the target sink, such as the rolling file sink, move the wrapped sink's configuration within a `WriteTo.Async()` statement: @@ -32,8 +32,6 @@ Because the memory buffer may contain events that have not yet been written to t ### Buffering -This sink uses a separate worker thread to write to your sink, freeing up the calling thread to run in your app without having to wait. - The default memory buffer feeding the worker thread is capped to 10,000 items, after which arriving events will be dropped. To increase or decrease this limit, specify it when configuring the async sink. ```csharp diff --git a/src/Serilog.Sinks.Async/Sinks/Async/BackgroundWorkerSink.cs b/src/Serilog.Sinks.Async/Sinks/Async/BackgroundWorkerSink.cs index 87e1bfe..4d150c9 100644 --- a/src/Serilog.Sinks.Async/Sinks/Async/BackgroundWorkerSink.cs +++ b/src/Serilog.Sinks.Async/Sinks/Async/BackgroundWorkerSink.cs @@ -4,6 +4,7 @@ using Serilog.Core; using Serilog.Debugging; using Serilog.Events; +using System.Threading.Tasks; namespace Serilog.Sinks.Async { @@ -14,7 +15,7 @@ sealed class BackgroundWorkerSink : ILogEventSink, IDisposable volatile bool _disposed; readonly CancellationTokenSource _cancel = new CancellationTokenSource(); readonly BlockingCollection _queue; - readonly Thread _worker; + readonly Task _worker; public BackgroundWorkerSink(Logger pipeline, int bufferCapacity) { @@ -23,8 +24,7 @@ public BackgroundWorkerSink(Logger pipeline, int bufferCapacity) _pipeline = pipeline; _bufferCapacity = bufferCapacity; _queue = new BlockingCollection(_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) @@ -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 } diff --git a/src/Serilog.Sinks.Async/project.json b/src/Serilog.Sinks.Async/project.json index 8ad6739..37fcd51 100644 --- a/src/Serilog.Sinks.Async/project.json +++ b/src/Serilog.Sinks.Async/project.json @@ -1,5 +1,5 @@ -{ - "version": "1.0.1-*", +{ + "version": "1.1.0-*", "description": "Asynchronous sink wrapper for Serilog.", "authors": [ "Jezz Santos", "Serilog Contributors" ], @@ -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" } } }