Author : MD TAREQ HASSAN
Enricher
- Log events can be enriched with properties
- Enricher adds content to every log
Serilog project provides:
- Serilog.Enrichers.Environment
- Serilog.Enrichers.Process
- Serilog.Enrichers.Thread
- Serilog.Enrichers.Context
- The LogContext
Other enrichers:
Installation
Install-Package Serilog.Enrichers.Environment
Install-Package Serilog.Enrichers.Process
Install-Package Serilog.Enrichers.Thread
Install-Package Serilog.Enrichers.AspnetcoreHttpcontext
Install-Package Serilog.Exceptions
Using Enricher
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.Enrich.WithThreadId()
.Enrich.FromLogContext()
.CreateLogger();
ILogEventEnricher
Log.Logger = new LoggerConfiguraition()
.Enrich.FromLogContext()
// ...
private readonly ILogger _log = Log.ForContext<HomeController>();