I create a custom Middliware to Push info about HttpContext into my Serilog LogContext:
if (context == null) throw new ArgumentNullException(nameof(context));
string profile = context.Request.Host.Host;
string ipAddress = context.Connection.RemoteIpAddress?.ToString();
string userAgent = context.Request.Headers["User-Agent"].ToString();
using (LogContext.PushProperty("Profile", profile))
using (LogContext.PushProperty("IpAddress", ipAddress))
using (LogContext.PushProperty("UserAgent", userAgent))
{
await _next(context);
}
I want to understand the behavior of my LogContext properties in various queries (Hhtp Requests).
From Microsoft Docs:
AsyncLocal Represents ambient data that is local to a given asynchronous control flow, such as an asynchronous method.
What is my asynchronous control flow in Blazor Server Middleware?