Skip to content

Commit 96b9e77

Browse files
authored
Some further README updates [Skip CI]
1 parent e6c49e1 commit 96b9e77

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
1-
# 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)
1+
# 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)
22

3-
Use this buffered, async, delegating, sink to reduce the time it takes for your app to write your log events to your sinks. This sink can work with any `ILogEventSink` you use.
3+
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.
44

5-
Especially suited to non-batching sinks that are either slow to write or have I/O bottlenecks (like http, databases, file writes etc.).
5+
**Note:** many of the network-based sinks (_CouchDB_, _Elasticsearch_, _MongoDB_, _Seq_, _Splunk_...) already perform asychronous batching natively and do not benefit from this wrapper.
66

7-
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.
7+
### Getting started
88

9-
Install from NuGet:
9+
Install from [NuGet](https://nuget.org/packages/serilog.sinks.async):
1010

1111
```powershell
1212
Install-Package Serilog.Sinks.Async -Pre
1313
```
1414

15-
Add this sink to your pipeline:
15+
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:
1616

1717
```csharp
1818
Log.Logger = new LoggerConfiguration()
19-
.WriteTo.Async(x => x.YourSink())
19+
.WriteTo.Async(a => a.RollingFile("logs/myapp-{Date}.txt"))
2020
// Other logger configuration
2121
.CreateLogger()
22+
23+
Log.Information("This will be writtend to disk on the worker thread");
24+
25+
// At application shutdown
26+
Log.CloseAndFlush();
2227
```
2328

24-
Now `YourSink` will write messages using a worker thread while your applicatoin thread gets on with more important stuff.
29+
The wrapped sink (`RollingFile` in this case) will be invoked on a worker thread while your application's thread gets on with more important stuff.
30+
31+
Because the memory buffer may contain events that have not yet been written to the target sink, it is important to call `Log.CloseAndFlush()` or `Logger.Dispose()` when the application exits.
32+
33+
### Buffering
34+
35+
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.
2536

2637
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.
2738

2839
```csharp
29-
Log.Logger = new LoggerConfiguration()
30-
.WriteTo.Async(x => x.YourSink(), 500) // Max number of events to buffer in memory
31-
// Other logger configurationg
32-
.CreateLogger()
40+
// Reduce the buffer to 500 events
41+
.WriteTo.Async(a => a.RollingFile("logs/myapp-{Date}.txt"), 500)
3342
```
3443

35-
## About this sink
44+
### XML `<appSettings> and JSON configuration
45+
46+
XML and JSON configuration support has not yet been added for this wrapper.
47+
48+
### About this sink
3649

37-
This sink was created following this conversation thread: https://github.com/serilog/serilog/issues/809
50+
This sink was created following this conversation thread: https://github.com/serilog/serilog/issues/809.

0 commit comments

Comments
 (0)