Skip to content

Commit

Permalink
Handle missing HttpContext in log enricher (#1590)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad authored Oct 17, 2024
1 parent a173850 commit 428f566
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ public class AddUserIdLogEventEnricher(IHttpContextAccessor httpContextAccessor)
{
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var httpContext = httpContextAccessor.HttpContext ?? throw new InvalidOperationException("No HttpContext.");
var httpContext = httpContextAccessor.HttpContext;

if (httpContext is null)
{
return;
}

var principal = httpContext.User;

if (principal?.Identity is null || !principal.Identity.IsAuthenticated)
Expand Down

0 comments on commit 428f566

Please sign in to comment.