Use this to enrich logs with a Correlation Id
Configure serilog is as follows;
"serilog": {
"minimumLevel": { },
"writeTo": [ ],
"enrich": [ "WithCorrelation" ]
}
There is also a fix in this libarey for a known issue with ASP.NET core 2.2.0, which results in the correlation is not being set. To use the fix, do the following in your Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddDiagnosticObserver<CorrelationIdObserver>();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider, IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory)
{
serviceProvider.UseDiagnosticObserver<CorrelationIdObserver>();
}
To install from nuget;
Install-Package Serilog.Enrichers.Correlation