![]() |
VOOZH | about |
dotnet add package Serilog.Sinks.Async --version 2.1.0
NuGet\Install-Package Serilog.Sinks.Async -Version 2.1.0
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
<PackageVersion Include="Serilog.Sinks.Async" Version="2.1.0" />Directory.Packages.props
<PackageReference Include="Serilog.Sinks.Async" />Project file
paket add Serilog.Sinks.Async --version 2.1.0
#r "nuget: Serilog.Sinks.Async, 2.1.0"
#:package Serilog.Sinks.Async@2.1.0
#addin nuget:?package=Serilog.Sinks.Async&version=2.1.0Install as a Cake Addin
#tool nuget:?package=Serilog.Sinks.Async&version=2.1.0Install as a Cake Tool
An asynchronous wrapper for other Serilog 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 and RollingFile sinks that may be affected by I/O bottlenecks.
Note: many of the network-based sinks (CouchDB, Elasticsearch, MongoDB, Seq, Splunk...) already perform asynchronous batching natively and do not benefit from this wrapper.
Install from NuGet:
dotnet add package Serilog.Sinks.Async
Assuming you have already installed the target sink, such as the file sink, move the wrapped sink's configuration within a WriteTo.Async() statement:
Log.Logger = new LoggerConfiguration()
.WriteTo.Async(a => a.File("logs/myapp.log"))
// Other logger configuration
.CreateLogger()
Log.Information("This will be written to disk on the worker thread");
// At application shutdown (results in monitors getting StopMonitoring calls)
Log.CloseAndFlush();
The wrapped sink (File in this case) will be invoked on a worker thread while your application's thread gets on with more important stuff.
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.
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. One can determine whether events have been dropped via Serilog.Async.IAsyncLogEventSinkInspector.DroppedMessagesCount (see Sink State Inspection interface below).
// Reduce the buffer to 500 events
.WriteTo.Async(a => a.File("logs/myapp.log"), bufferSize: 500)
The Async wrapper is primarily intended to allow one to achieve minimal logging latency at all times, even when writing to sinks that may momentarily block during the course of their processing (e.g., a File Sink might block for a low number of ms while flushing). The dropping behavior is an important failsafe; it avoids having an unbounded buffering behaviour should logging throughput overwhelm the sink, or the sink ingestion throughput degrade.
In practice, this configuration (assuming one provisions an adequate bufferSize) achieves an efficient and resilient logging configuration that can safely handle load without impacting processing throughput. The risk is of course that events get be dropped if the buffer threshold gets breached. The inspection interface, IAsyncLogEventSinkInspector (obtained by providing an IAsyncLogEventSinkMonitor when configuring the Async Sink), enables a health monitoring mechanism to actively validate that the buffer allocation is not being exceeded in practice.
// Example check: log message to an out of band alarm channel if logging is showing signs of getting overwhelmed
void ExecuteAsyncBufferCheck(IAsyncLogEventSinkInspector inspector)
{
var usagePct = inspector.Count * 100 / inspector.BufferSize;
if (usagePct > 50) SelfLog.WriteLine("Log buffer exceeded {0:p0} usage (limit: {1})", usagePct, inspector.BufferSize);
}
class MonitorConfiguration : IAsyncLogEventSinkMonitor
{
public void StartMonitoring(IAsyncLogEventSinkInspector inspector) =>
HealthMonitor.AddPeriodicCheck(() => ExecuteAsyncBufferCheck(inspector));
public void StopMonitoring(IAsyncLogEventSinkInspector inspector)
{ /* reverse of StartMonitoring */ }
}
// Provide monitor so we can wire the health check to the inspector
var monitor = new MonitorConfiguration();
// Use default config (drop events if >10,000 backlog)
.WriteTo.Async(a => a.File("logs/myapp.log"), monitor: monitor) ...
Warning: For the same reason one typically does not want exceptions from logging to leak into the execution path, one typically does not want a logger to be able to have the side-effect of actually interrupting application processing until the log propagation has been unblocked.
When the buffer size limit is reached, the default behavior is to drop any further attempted writes until the queue abates, reporting each such failure to the Serilog.Debugging.SelfLog. To replace this with a blocking behaviour, set blockWhenFull to true.
// Wait for any queued event to be accepted by the `File` log before allowing the calling thread to resume its
// application work after a logging call when there are 10,000 LogEvents awaiting ingestion by the pipeline
.WriteTo.Async(a => a.File("logs/myapp.log"), blockWhenFull: true)
<appSettings> and JSON configurationUsing Serilog.Settings.Configuration JSON:
{
"Serilog": {
"WriteTo": [{
"Name": "Async",
"Args": {
"configure": [{
"Name": "Console"
}]
}
}]
}
}
XML configuration support has not yet been added for this wrapper.
This sink was created following this conversation thread: https://github.com/serilog/serilog/issues/809.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 is compatible. net463 net463 was computed. net47 net47 was computed. net471 net471 is compatible. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Serilog.Sinks.Async:
| Package | Downloads |
|---|---|
|
Serilog.Extensions.Logging.File
Add file logging to ASP.NET Core apps with one line of code. |
|
|
Umbraco.Cms.Web.Common
Contains the web assembly needed to run Umbraco CMS. |
|
|
Umbraco.Cms.Infrastructure
Contains the infrastructure assembly needed to run Umbraco CMS. |
|
|
Umbraco.Cms.Examine.Lucene
Adds Examine searching support using Lucene to Umbraco CMS. |
|
|
Umbraco.Cms.Web.Website
Contains the website assembly needed to run the frontend of Umbraco CMS. |
Showing the top 20 popular GitHub repositories that depend on Serilog.Sinks.Async:
| Repository | Stars |
|---|---|
|
jellyfin/jellyfin
The Free Software Media System - Server Backend & API
|
|
|
netchx/netch
A simple proxy client
|
|
|
abpframework/abp
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
|
|
|
felixse/FluentTerminal
A Terminal Emulator based on UWP and web technologies.
|
|
|
kurrent-io/KurrentDB
KurrentDB is a database that's engineered for modern software applications and event-driven architectures. Its event-native design simplifies data modeling and preserves data integrity while the integrated streaming engine solves distributed messaging challenges and ensures data consistency.
|
|
|
anjoy8/Blog.Core
💖 ASP.NET Core 8.0 全家桶教程,前后端分离后端接口,vue教程姊妹篇,官方文档:
|
|
|
umbraco/Umbraco-CMS
Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
|
|
|
BililiveRecorder/BililiveRecorder
录播姬 | mikufans 生放送录制
|
|
|
HMBSbige/NatTypeTester
测试当前网络的 NAT 类型(STUN)
|
|
|
MvvmCross/MvvmCross
The .NET MVVM framework for cross-platform solutions, including Android, iOS, MacCatalyst, macOS, tvOS, WPF, WinUI
|
|
|
oskardudycz/EventSourcing.NetCore
Examples and Tutorials of Event Sourcing in .NET
|
|
|
fullstackhero/blazor-starter-kit
Clean Architecture Template for Blazor WebAssembly Built with MudBlazor Components.
|
|
|
slskd/slskd
A modern client-server application for the Soulseek file sharing network.
|
|
|
ChangemakerStudios/Papercut-SMTP
Papercut SMTP -- The Simple Desktop Email Server
|
|
|
intel/acat
Assistive Context-Aware Toolkit (ACAT)
|
|
|
goatcorp/FFXIVQuickLauncher
Custom launcher for FFXIV
|
|
|
microsoft/kernel-memory
Research project. A Memory solution for users, teams, and applications.
|
|
|
SubnauticaNitrox/Nitrox
An open-source, multiplayer modification for the game Subnautica.
|
|
|
microsoft/sbom-tool
The SBOM tool is a highly scalable and enterprise ready tool to create SPDX 2.2 compatible SBOMs for any variety of artifacts.
|
|
|
LAB02-Research/HASS.Agent
Windows-based client for Home Assistant. Provides notifications, quick actions, commands, sensors and more.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.0 | 35,730,040 | 10/24/2024 |
| 2.1.0-dev-00098 | 581 | 10/23/2024 |
| 2.1.0-dev-00096 | 988 | 10/21/2024 |
| 2.0.0 | 12,001,009 | 6/6/2024 |
| 2.0.0-dev-00091 | 451 | 6/6/2024 |
| 1.5.0 | 92,101,274 | 6/25/2021 |
| 1.5.0-dev-00080 | 8,835 | 6/25/2021 |
| 1.4.1-dev-00079 | 18,471 | 5/13/2021 |
| 1.4.1-dev-00073 | 210,518 | 5/7/2020 |
| 1.4.1-dev-00071 | 123,075 | 11/8/2019 |
| 1.4.0 | 37,152,785 | 6/9/2019 |
| 1.4.0-dev-00067 | 1,809 | 6/7/2019 |
| 1.3.1-dev-00063 | 72,776 | 9/22/2018 |
| 1.3.1-dev-00061 | 7,326 | 8/8/2018 |
| 1.3.0 | 7,789,252 | 5/21/2018 |
| 1.3.0-dev-00056 | 2,067 | 5/18/2018 |
| 1.2.0 | 626,893 | 5/9/2018 |
| 1.2.0-dev-00051 | 2,280 | 5/9/2018 |
| 1.2.0-dev-00049 | 2,290 | 5/9/2018 |
| 1.2.0-dev-00048 | 2,472 | 4/25/2018 |