Logging in .NET
Structured Logging
When logging and using a provider that supports structured/semantic logging, we should provide parameters the following way:
The first way stores both the value of the parameter (the actual user
identifier) and the name of this parameter. In the second approach, the name is
lost, so we are not able to filter based on the named parameter (userId
).
Log Storage
Structured logs can be stored in systems like:
- Elasticsearch
- Seq
Serilog
Using Serilog:
-
Install NuGet packages:
-
Use Serilog with DI
-
Configure
In
appsettings.json
:More information can be found here.