Serilog.Enrichers.Thread
4.0.0
Prefix Reserved
dotnet add package Serilog.Enrichers.Thread --version 4.0.0
NuGet\Install-Package Serilog.Enrichers.Thread -Version 4.0.0
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
paket add Serilog.Enrichers.Thread --version 4.0.0
#r "nuget: Serilog.Enrichers.Thread, 4.0.0"
// Install Serilog.Enrichers.Thread as a Cake Addin #addin nuget:?package=Serilog.Enrichers.Thread&version=4.0.0 // Install Serilog.Enrichers.Thread as a Cake Tool #tool nuget:?package=Serilog.Enrichers.Thread&version=4.0.0
Serilog.Enrichers.Thread
Enrich Serilog events with properties from the current thread.
Getting started
Install the package from NuGet:
Install-Package Serilog.Enrichers.Thread
In your logger configuration, apply Enrich.WithThreadId()
and Enrich.WithThreadName()
:
Log.Logger = new LoggerConfiguration()
.Enrich.WithThreadId()
.Enrich.WithThreadName()
.CreateLogger();
Many sinks simply include all properties without further action required, so the thread id will be logged automatically.
However, some sinks, such as the File and Console sinks use an output template and the new ThreadId
may not be automatically output in your sink. In this case, in order for the ThreadId
or ThreadName
to show up in the logging, you will need to create or modify your output template.
w.File(...., outputTemplate:
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj} {Properties}{NewLine}{Exception}")
Here, {Properties} can include not only ThreadId
and ThreadName
, but any other enrichment which is applied. Alternatively, {ThreadId} could be used instead, if you want to only add the thread id enrichment and {ThreadName}, if you want to only add the thread name enrichment.
An example, which also uses the Serilogs.Sinks.Async Nuget package, is below:
Thread.CurrentThread.Name = "MyWorker";
var logger = Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console(restrictedToMinimumLevel:Serilog.Events.LogEventLevel.Information)
.WriteTo.Async(w=>w.File("..\\..\\..\\..\\logs\\SerilogLogFile.json", rollingInterval: RollingInterval.Day, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj} <{ThreadId}><{ThreadName}>{NewLine}{Exception}"))
.Enrich.WithThreadId()
.CreateLogger();
Which would produce an output in the log file as follows:
2018-04-06 13:12:45.684 +02:00 [ERR] The file file_name.svg does not exist <4><MyWorker>
Where, <4> is an example thread id and <MyWorker> is an example thread name.
To use the enricher, first install the NuGet package:
Install-Package Serilog.Enrichers.Thread
Note: The {ThreadName} property will only be attached when it is not null. Otherwise it will be omitted. If you want to get this property always attached you can use the following:
using Serilog.Enrichers;
Log.Logger = new LoggerConfiguration()
.Enrich.WithThreadName()
.Enrich.WithProperty(ThreadNameEnricher.ThreadNamePropertyName, "MyDefault")
.CreateLogger();
The enrichment order is important. Otherwise "MyDefault" would always win.
Copyright © 2016 Serilog Contributors - Provided under the Apache License, Version 2.0.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 is compatible. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
NuGet packages (273)
Showing the top 5 NuGet packages that depend on Serilog.Enrichers.Thread:
Package | Downloads |
---|---|
Umbraco.Cms.Infrastructure
Contains the infrastructure assembly needed to run Umbraco CMS. |
|
UmbracoCms.Core
Contains the core assemblies needed to run Umbraco Cms. This package only contains assemblies and can be used for package development. Use the UmbracoCms package to setup Umbraco in Visual Studio as an ASP.NET project. |
|
IppDotNetSdkForQuickBooksApiV3
The IPP .NET SDK for QuickBooks V3 is a set of .NET classes that make it easier to call QuickBooks APIs. This is the .Net Standard 2.0 version of the .Net SDK |
|
NBomber
Modern and flexible load testing framework for Pull and Push scenarios, designed to test any system regardless a protocol (HTTP/WebSockets/AMQP etc) or a semantic model (Pull/Push). |
|
Be.Vlaanderen.Basisregisters.Api
Common API infrastructure and helpers. |
GitHub repositories (60)
Showing the top 5 popular GitHub repositories that depend on Serilog.Enrichers.Thread:
Repository | Stars |
---|---|
jellyfin/jellyfin
The Free Software Media System
|
|
Kareadita/Kavita
Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
|
|
ServiceStack/ServiceStack
Thoughtfully architected, obscenely fast, thoroughly enjoyable web services for all
|
|
EventStore/EventStore
EventStoreDB, the event-native database. Designed for Event Sourcing, Event-Driven, and Microservices architectures
|
|
immense/Remotely
A remote control and remote scripting solution, built with .NET 8, Blazor, and SignalR.
|
Version | Downloads | Last updated |
---|---|---|
4.0.0 | 1,307,344 | 6/14/2024 |
4.0.0-dev-00770 | 82 | 6/14/2024 |
4.0.0-dev-00767 | 83 | 6/14/2024 |
4.0.0-dev-00762 | 84 | 6/14/2024 |
3.2.0-dev-00756 | 158,389 | 11/14/2023 |
3.2.0-dev-00752 | 657,196 | 5/11/2021 |
3.2.0-dev-00750 | 3,162,286 | 2/26/2021 |
3.2.0-dev-00747 | 723,292 | 9/2/2019 |
3.1.1-dev-00745 | 56,769 | 6/2/2019 |
3.1.1-dev-00743 | 5,018 | 5/8/2019 |
3.1.0 | 88,757,397 | 5/2/2019 |
3.1.0-dev-00739 | 702 | 5/2/2019 |
3.0.1-dev-00737 | 10,998 | 2/24/2019 |
3.0.1-dev-00731 | 1,457 | 2/8/2019 |
3.0.1-dev-00728 | 31,435 | 5/9/2018 |
3.0.1-dev-00727 | 7,002 | 4/6/2018 |
3.0.0 | 10,138,403 | 11/13/2016 |
3.0.0-dev-00721 | 1,506 | 11/11/2016 |
2.0.1-dev-00720 | 1,017 | 11/11/2016 |
2.0.0 | 284,105 | 6/28/2016 |
2.0.0-rc-712 | 1,385 | 5/27/2016 |
2.0.0-beta-705 | 1,173 | 5/17/2016 |
2.0.0-beta-701 | 1,152 | 4/11/2016 |
2.0.0-beta-700 | 1,342 | 3/23/2016 |
2.0.0-beta-521 | 1,013 | 3/18/2016 |
2.0.0-beta-519 | 1,136 | 3/16/2016 |
2.0.0-beta-516 | 1,011 | 3/15/2016 |
2.0.0-beta-515 | 974 | 3/15/2016 |
2.0.0-beta-513 | 987 | 3/15/2016 |
2.0.0-beta-511 | 1,035 | 3/14/2016 |
2.0.0-beta-509 | 1,084 | 3/13/2016 |
2.0.0-beta-507 | 1,326 | 3/1/2016 |
2.0.0-beta-505 | 1,358 | 2/25/2016 |
2.0.0-beta-502 | 1,064 | 2/22/2016 |
2.0.0-beta-499 | 1,002 | 2/21/2016 |