You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enrich Serilog events with properties from the current thread.
4
+
5
+
`WithThreadName()` is only supported in .NetStandard 2.0 and .NetFramework 4.5.
4
6
5
7
### Getting started
6
8
@@ -10,43 +12,59 @@ Install the package from NuGet:
10
12
Install-Package Serilog.Enrichers.Thread
11
13
```
12
14
13
-
In your logger configuration, apply `Enrich.WithThreadId()`:
15
+
In your logger configuration, apply `Enrich.WithThreadId()` and `Enrich.WithThreadName()`:
14
16
15
17
```csharp
16
18
Log.Logger=newLoggerConfiguration()
17
19
.Enrich.WithThreadId()
20
+
.Enrich.WithThreadName()
18
21
.CreateLogger();
19
22
```
23
+
20
24
Many sinks simply include all properties without further action required, so the thread id will be logged automatically.
21
-
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 to show up in the logging, you will need to create or modify your output template.
25
+
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.
Here, {Properties} can include not only ThreadId, but any other enrichment which is applied. Alternatively, {ThreadId} could be used instead, if you want to only add the thread id enrichment.
31
+
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.
28
32
29
33
An example, which also uses the Serilogs.Sinks.Async Nuget package, is below:
0 commit comments