Skip to content

Commit 5bd2f4d

Browse files
Copilotmarcominerva
andcommitted
Add User-Agent property to Serilog logging
Co-authored-by: marcominerva <3522534+marcominerva@users.noreply.github.com>
1 parent 330a978 commit 5bd2f4d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/PdfSmith/Logging/HttpContextLogEventEnricher.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,10 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
1515
}
1616

1717
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("UserName", httpContext.User?.Identity?.Name));
18+
19+
if (httpContext.Request?.Headers?.TryGetValue("User-Agent", out var userAgent) == true)
20+
{
21+
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("User-Agent", userAgent.ToString()));
22+
}
1823
}
1924
}

0 commit comments

Comments
 (0)