Add User-Agent property to Serilog logging#34
Merged
marcominerva merged 2 commits intomasterfrom Oct 9, 2025
Merged
Conversation
Co-authored-by: marcominerva <3522534+marcominerva@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add User-Agent property to Serilog logging
Add User-Agent property to Serilog logging
Oct 9, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances Serilog logging by adding User-Agent header information to log events for improved request traceability and diagnostics.
Key Changes
- Updated
HttpContextLogEventEnricherto extract User-Agent headers from HTTP requests - Added User-Agent as a log property when the header is present
- Implementation follows existing patterns in the codebase with proper null handling
marcominerva
approved these changes
Oct 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR enhances Serilog logging by including the User-Agent header from HTTP requests as a property in log events, improving traceability and diagnostics.
Changes
Updated
HttpContextLogEventEnricherto extract the User-Agent header from incoming HTTP requests and add it as a property named "User-Agent" to all relevant Serilog log events.Implementation Details
The implementation follows the existing pattern used for other HTTP context enrichment in the codebase:
httpContext.Request?.Headers?.TryGetValue()AddPropertyIfAbsent()to avoid conflicts if the property is already setBenefits
Testing
.editorconfigTimeZoneService)Fixes issue regarding User-Agent property in Serilog logging.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.