From 6fe63824853f0234cc2a8bf78b804ee292565f9d Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Mon, 7 Apr 2025 18:57:08 +0000 Subject: [PATCH] add remote ip and user agent to http request logging (#1990) --- CHANGELOG.md | 1 + ErsatzTV/Startup.cs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c9f7c76..93e2fe17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/ErsatzTV/Startup.cs b/ErsatzTV/Startup.cs index c9060eda..872a7d72 100644 --- a/ErsatzTV/Startup.cs +++ b/ErsatzTV/Startup.cs @@ -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(