Skip to content

Commit

Permalink
Merge pull request #17 from serilog/dev
Browse files Browse the repository at this point in the history
1.1.0 Release
  • Loading branch information
nblumhardt committed Jun 26, 2017
2 parents bb2896e + a0c1aa7 commit 752c27f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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:
Expand All @@ -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
Expand Down
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
15 changes: 4 additions & 11 deletions src/Serilog.Sinks.Async/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.1-*",
{
"version": "1.1.0-*",

"description": "Asynchronous sink wrapper for Serilog.",
"authors": [ "Jezz Santos", "Serilog Contributors" ],
Expand All @@ -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 752c27f

Please sign in to comment.