Skip to content

Commit e1c0fc2

Browse files
authored
Merge pull request #8 from asterixorobelix/patch-1
Update README.md
2 parents d0c2393 + 170dd90 commit e1c0fc2

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,31 @@ Log.Logger = new LoggerConfiguration()
1717
.Enrich.WithThreadId()
1818
.CreateLogger();
1919
```
20-
20+
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.
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-06 13:12:45.684 +02:00 [ERR] The file file_name.svg does not exist <4>
42+
```
43+
Where, <4> is an example thread id.
44+
2145
To use the enricher, first install the NuGet package:
2246

2347
```powershell

0 commit comments

Comments
 (0)