Get Property after Serilog LogContext.PushProperty

Viewed 249

I'm using .NET Core 3.1 with Serilog in a Worker application, this Worker application just read from a file and make inserts in a database.

So, each time this JOB runs I'm writing a CorrelationID in Serilog, in this way:

LogContext.PushProperty("CorrelationId", Guid.NewGuid().ToString());

This works fine because I'm using config.Enrich.FromLogContext() in Startup.cs. But now I need to retrieve correlationId information from another class and I can't found any method to do it, something like: LogContext.GetProperty(...)

All examples that I found in my google search use the HttpContext, but remember that I'm in a Worker Application, so I don't have HttpContext.

0 Answers
Related