-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
Hi,
im wondering if it would be possible to add some graceful way for retrieving correlation id.
Im using it to show user information about error, so admin can get all the logs from the request correlated with it. Currently the only way is to set correlation id manually (which i would like to avoid), or to retrieve it in in some hacky way like this:
private static Guid GetCorrelationId(HttpContext ctx)
{
if (ctx.Items.TryGetValue("Serilog_CorrelationId", out var correlationIdItem) &&
correlationIdItem is LogEventProperty { Name: "CorrelationId" } correlationIdProperty)
{
var correlationId = ((ScalarValue)correlationIdProperty.Value).Value as string;
return Guid.Parse(correlationId ?? throw new InvalidOperationException("Invalid correlation ID format."));
}
return Guid.NewGuid();
}
Copilot
Metadata
Metadata
Assignees
Labels
No labels