I am trying to figure out which approach is best:
I have an Owin pipeline where I would like to enrich all logs with various information based on the request (URL, IP address, etc.).
As I can see, I have two options with Serilog ForContext()in the Owin pipeline:
public override async Task Invoke(IOwinContext context)
{
using (LogContext.PushProperties(
RequestUri(context),
RemoteIp(context)))
{
await Next.Invoke(context);
}
}
Or configure the enrichment when setting up Serilog:
var configuration = new LoggerConfiguration()
.Enrich.WithRequestUrl()
.Enrich.WithRequestClientIp()
...
Is there a right or wrong way to do this? Personally, I like LogContext, as I provide me with an easy way to access Owin content, but on the other hand, all my requests will initiate an evaluation of all enrichments. But then again, is this done only once during the request, and not for each registration operator?
- ?