add remote ip and user agent to http request logging (#1990)

This commit is contained in:
Jason Dove
2025-04-07 18:57:08 +00:00
committed by GitHub
parent 100ae0adda
commit 6fe6382485
2 changed files with 9 additions and 0 deletions
+1
View File
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add `linux-musl-x64` artifact for users running Alpine x64
- Add API endpoint to empty trash (POST to `/api/maintenance/empty_trash`)
- e.g. `curl -XPOST -d '' http://localhost:8409/api/maintenance/empty_trash`
- Add remote IP and user agent to HTTP request logging
### Fixed
- Fix error message about synchronizing Plex collections from a Plex server that has zero collections
+8
View File
@@ -506,6 +506,14 @@ public class Startup
return LogEventLevel.Verbose;
};
options.EnrichDiagnosticContext = (diagnosticContext, httpContext) =>
{
diagnosticContext.Set("RemoteIP", httpContext.Connection.RemoteIpAddress);
diagnosticContext.Set("UserAgent", httpContext.Request.Headers["User-Agent"]);
};
options.MessageTemplate = "HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.00} ms from {UserAgent} at {RemoteIP}";
});
app.UseRequestLocalization(