Skip to content

Commit 56d9dfe

Browse files
Update README.md
added more info to help explain how to get thread id to display in logging
1 parent d0c2393 commit 56d9dfe

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,29 @@ Log.Logger = new LoggerConfiguration()
1717
.Enrich.WithThreadId()
1818
.CreateLogger();
1919
```
20-
20+
21+
In order for the ThreadId to show up in the logging, you will need to create or modify your output template.
22+
23+
```csharp
24+
w.File(...., outputTemplate:
25+
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj} {Properties}{NewLine}{Exception}")
26+
```
27+
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.
28+
29+
An example, which also uses the Serilogs.Sinks.Async Nuget package, is below:
30+
31+
```csharp
32+
var logger = Log.Logger = new LoggerConfiguration()
33+
.MinimumLevel.Debug()
34+
.WriteTo.Console(restrictedToMinimumLevel:Serilog.Events.LogEventLevel.Information)
35+
.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}{NewLine}{Exception}"))
36+
.Enrich.WithThreadId()
37+
.CreateLogger();
38+
```
39+
Which would produce an output in the log file as follows:
40+
```
41+
2018-04-05 20:40:30.222 +02:00 [ERR] The file name_of_file.svg does not exist 1
42+
```
2143
To use the enricher, first install the NuGet package:
2244

2345
```powershell

0 commit comments

Comments
 (0)