From 9089e2ee04c8c456a8df7a60f1b6a8869469eff7 Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Sun, 4 Feb 2024 21:34:41 -0600 Subject: [PATCH] add iptv request logging (#1594) --- CHANGELOG.md | 1 + ErsatzTV/Program.cs | 1 + ErsatzTV/Startup.cs | 30 +++++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78915165..2e88ba72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Default value: `false` - When enabled, embedded text subtitles will be periodically extracted, and considered for playback - Add `sub_language` and `sub_language_tag` fields to search index +- Add `/iptv` request logging to streaming log category at debug level ### Fixed - Fix antiforgery error caused by reusing existing browser tabs across docker container restarts diff --git a/ErsatzTV/Program.cs b/ErsatzTV/Program.cs index c595663c..05213b14 100644 --- a/ErsatzTV/Program.cs +++ b/ErsatzTV/Program.cs @@ -77,6 +77,7 @@ public class Program .MinimumLevel.Override("ErsatzTV.Application.Streaming", LoggingLevelSwitches.StreamingLevelSwitch) .MinimumLevel.Override("ErsatzTV.FFmpeg", LoggingLevelSwitches.StreamingLevelSwitch) .MinimumLevel.Override("ErsatzTV.Controllers.IptvController", LoggingLevelSwitches.StreamingLevelSwitch) + .MinimumLevel.Override("Serilog.AspNetCore.RequestLoggingMiddleware", LoggingLevelSwitches.StreamingLevelSwitch) .Destructure.UsingAttributes() .Enrich.FromLogContext() diff --git a/ErsatzTV/Startup.cs b/ErsatzTV/Startup.cs index f6cca745..d0a9efbd 100644 --- a/ErsatzTV/Startup.cs +++ b/ErsatzTV/Startup.cs @@ -85,6 +85,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Refit; using Serilog; +using Serilog.Events; namespace ErsatzTV; @@ -492,7 +493,34 @@ public class Startup app.UseForwardedHeaders(); // app.UseHttpLogging(); - // app.UseSerilogRequestLogging(); + app.UseSerilogRequestLogging( + options => + { + options.IncludeQueryInRequestPath = true; + + // Emit debug-level events instead of the defaults + options.GetLevel = (httpContext, elapsed, ex) => + { + if (ex is not null) + { + return LogEventLevel.Error; + } + + if (httpContext.Response.StatusCode > 499) + { + return LogEventLevel.Error; + } + + if (httpContext.Request.Path.ToUriComponent().StartsWith( + "/iptv", + StringComparison.OrdinalIgnoreCase)) + { + return LogEventLevel.Debug; + } + + return LogEventLevel.Verbose; + }; + }); app.UseRequestLocalization( options =>