From 71d8e66d9fbca1d448d8d4ec7c1fe9be55134076 Mon Sep 17 00:00:00 2001 From: Vasily Date: Mon, 6 Apr 2020 14:42:41 +0300 Subject: [PATCH 1/5] Add logging of URL being processed when logging an error This might help diagnosing stuff like "Operation was cancelled" --- .../HttpServer/HttpListenerHost.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 72667a314..c12862145 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; using System.Net.Sockets; @@ -239,19 +240,22 @@ namespace Emby.Server.Implementations.HttpServer } } - private async Task ErrorHandler(Exception ex, IRequest httpReq, bool logExceptionStackTrace) + private async Task ErrorHandler(Exception ex, IRequest httpReq, bool logExceptionStackTrace, string urlToLog) { + string urlSuffix = string.IsNullOrWhiteSpace(urlToLog) + ? string.Format(CultureInfo.InvariantCulture, "; URL being processed: {0}", urlToLog) + : ""; try { ex = GetActualException(ex); if (logExceptionStackTrace) { - _logger.LogError(ex, "Error processing request"); + _logger.LogError(ex, "Error processing request{Suffix}", urlSuffix); } else { - _logger.LogError("Error processing request: {Message}", ex.Message); + _logger.LogError("Error processing request: {Message}{Suffix}", ex.Message, urlSuffix); } var httpRes = httpReq.Response; @@ -271,7 +275,7 @@ namespace Emby.Server.Implementations.HttpServer } catch (Exception errorEx) { - _logger.LogError(errorEx, "Error this.ProcessRequest(context)(Exception while writing error to the response)"); + _logger.LogError(errorEx, "Error this.ProcessRequest(context)(Exception while writing error to the response){Suffix}", urlSuffix); } } @@ -553,7 +557,7 @@ namespace Emby.Server.Implementations.HttpServer || ex is OperationCanceledException || ex is SecurityException || ex is FileNotFoundException; - await ErrorHandler(ex, httpReq, ignoreStackTrace).ConfigureAwait(false); + await ErrorHandler(ex, httpReq, ignoreStackTrace, urlToLog).ConfigureAwait(false); } finally { From 61d9c9df5b4ad4b79679cccbb2a624447c824b67 Mon Sep 17 00:00:00 2001 From: Vasily Date: Sun, 12 Apr 2020 23:26:45 +0300 Subject: [PATCH 2/5] Addressing review feedback --- .../HttpServer/HttpListenerHost.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index c12862145..dd60e7a18 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -242,9 +242,7 @@ namespace Emby.Server.Implementations.HttpServer private async Task ErrorHandler(Exception ex, IRequest httpReq, bool logExceptionStackTrace, string urlToLog) { - string urlSuffix = string.IsNullOrWhiteSpace(urlToLog) - ? string.Format(CultureInfo.InvariantCulture, "; URL being processed: {0}", urlToLog) - : ""; + string urlSuffix = string.Format(CultureInfo.InvariantCulture, "; URL being processed: {0}", urlToLog); try { ex = GetActualException(ex); @@ -460,7 +458,7 @@ namespace Emby.Server.Implementations.HttpServer var stopWatch = new Stopwatch(); stopWatch.Start(); var httpRes = httpReq.Response; - string urlToLog = null; + string urlToLog = GetUrlToLog(urlString); string remoteIp = httpReq.RemoteIp; try @@ -506,8 +504,6 @@ namespace Emby.Server.Implementations.HttpServer return; } - urlToLog = GetUrlToLog(urlString); - if (string.Equals(localPath, _baseUrlPrefix + "/", StringComparison.OrdinalIgnoreCase) || string.Equals(localPath, _baseUrlPrefix, StringComparison.OrdinalIgnoreCase) || string.Equals(localPath, "/", StringComparison.OrdinalIgnoreCase) From 30f439287266a8afd6f6e7bea01ed08eb86bf0d7 Mon Sep 17 00:00:00 2001 From: Vasily Date: Sun, 12 Apr 2020 23:35:41 +0300 Subject: [PATCH 3/5] Fix condition flipped by https://github.com/jellyfin/jellyfin/pull/2635 --- Emby.Server.Implementations/HttpServer/HttpListenerHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index dd60e7a18..229e5d199 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -553,7 +553,7 @@ namespace Emby.Server.Implementations.HttpServer || ex is OperationCanceledException || ex is SecurityException || ex is FileNotFoundException; - await ErrorHandler(ex, httpReq, ignoreStackTrace, urlToLog).ConfigureAwait(false); + await ErrorHandler(ex, httpReq, !ignoreStackTrace, urlToLog).ConfigureAwait(false); } finally { From 058c35e739d4d3193e236b106cacd7ebc3926705 Mon Sep 17 00:00:00 2001 From: Vasily Date: Sun, 12 Apr 2020 23:40:34 +0300 Subject: [PATCH 4/5] Fix log highlithing --- .../HttpServer/HttpListenerHost.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 229e5d199..95df6fbc4 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Globalization; using System.IO; using System.Linq; using System.Net.Sockets; @@ -242,18 +241,17 @@ namespace Emby.Server.Implementations.HttpServer private async Task ErrorHandler(Exception ex, IRequest httpReq, bool logExceptionStackTrace, string urlToLog) { - string urlSuffix = string.Format(CultureInfo.InvariantCulture, "; URL being processed: {0}", urlToLog); try { ex = GetActualException(ex); if (logExceptionStackTrace) { - _logger.LogError(ex, "Error processing request{Suffix}", urlSuffix); + _logger.LogError(ex, "Error processing request; URL being processed: {Url}", urlToLog); } else { - _logger.LogError("Error processing request: {Message}{Suffix}", ex.Message, urlSuffix); + _logger.LogError("Error processing request: {Message}; URL being processed: {Url}", ex.Message, urlToLog); } var httpRes = httpReq.Response; @@ -273,7 +271,7 @@ namespace Emby.Server.Implementations.HttpServer } catch (Exception errorEx) { - _logger.LogError(errorEx, "Error this.ProcessRequest(context)(Exception while writing error to the response){Suffix}", urlSuffix); + _logger.LogError(errorEx, "Error this.ProcessRequest(context)(Exception while writing error to the response); URL being processed: {Url}", urlToLog); } } From 3bdb5e80a53fe8148048fc4424b1e92adc62ac3d Mon Sep 17 00:00:00 2001 From: Vasily Date: Mon, 13 Apr 2020 00:45:09 +0300 Subject: [PATCH 5/5] More consise error messages --- Emby.Server.Implementations/HttpServer/HttpListenerHost.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 95df6fbc4..5ae65a4e3 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -247,11 +247,11 @@ namespace Emby.Server.Implementations.HttpServer if (logExceptionStackTrace) { - _logger.LogError(ex, "Error processing request; URL being processed: {Url}", urlToLog); + _logger.LogError(ex, "Error processing request. URL: {Url}", urlToLog); } else { - _logger.LogError("Error processing request: {Message}; URL being processed: {Url}", ex.Message, urlToLog); + _logger.LogError("Error processing request: {Message}. URL: {Url}", ex.Message.TrimEnd('.'), urlToLog); } var httpRes = httpReq.Response; @@ -271,7 +271,7 @@ namespace Emby.Server.Implementations.HttpServer } catch (Exception errorEx) { - _logger.LogError(errorEx, "Error this.ProcessRequest(context)(Exception while writing error to the response); URL being processed: {Url}", urlToLog); + _logger.LogError(errorEx, "Error this.ProcessRequest(context)(Exception while writing error to the response). URL: {Url}", urlToLog); } }