Преглед изворни кода

Merge pull request #2783 from JustAMan/better-cancel-msg

Add logging of URL being processed when logging an error

(cherry picked from commit 2be6550db4afabc48f7c5122b0eed577db9a9a2e)
Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
Joshua M. Boniface пре 5 година
родитељ
комит
67194994f9
1 измењених фајлова са 12 додато и 8 уклоњено
  1. 12 8
      Emby.Server.Implementations/HttpServer/HttpListenerHost.cs

+ 12 - 8
Emby.Server.Implementations/HttpServer/HttpListenerHost.cs

@@ -223,7 +223,7 @@ 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)
         {
         {
             try
             try
             {
             {
@@ -231,11 +231,11 @@ namespace Emby.Server.Implementations.HttpServer
 
 
                 if (logExceptionStackTrace)
                 if (logExceptionStackTrace)
                 {
                 {
-                    _logger.LogError(ex, "Error processing request");
+                    _logger.LogError(ex, "Error processing request. URL: {Url}", urlToLog);
                 }
                 }
                 else
                 else
                 {
                 {
-                    _logger.LogError("Error processing request: {Message}", ex.Message);
+                    _logger.LogError("Error processing request: {Message}. URL: {Url}", ex.Message.TrimEnd('.'), urlToLog);
                 }
                 }
 
 
                 var httpRes = httpReq.Response;
                 var httpRes = httpReq.Response;
@@ -255,7 +255,7 @@ namespace Emby.Server.Implementations.HttpServer
             }
             }
             catch (Exception errorEx)
             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). URL: {Url}", urlToLog);
             }
             }
         }
         }
 
 
@@ -440,7 +440,7 @@ namespace Emby.Server.Implementations.HttpServer
             var stopWatch = new Stopwatch();
             var stopWatch = new Stopwatch();
             stopWatch.Start();
             stopWatch.Start();
             var httpRes = httpReq.Response;
             var httpRes = httpReq.Response;
-            string urlToLog = null;
+            string urlToLog = GetUrlToLog(urlString);
             string remoteIp = httpReq.RemoteIp;
             string remoteIp = httpReq.RemoteIp;
 
 
             try
             try
@@ -486,8 +486,6 @@ namespace Emby.Server.Implementations.HttpServer
                     return;
                     return;
                 }
                 }
 
 
-                urlToLog = GetUrlToLog(urlString);
-
                 if (string.Equals(localPath, _baseUrlPrefix + "/", StringComparison.OrdinalIgnoreCase)
                 if (string.Equals(localPath, _baseUrlPrefix + "/", StringComparison.OrdinalIgnoreCase)
                     || string.Equals(localPath, _baseUrlPrefix, StringComparison.OrdinalIgnoreCase)
                     || string.Equals(localPath, _baseUrlPrefix, StringComparison.OrdinalIgnoreCase)
                     || string.Equals(localPath, "/", StringComparison.OrdinalIgnoreCase)
                     || string.Equals(localPath, "/", StringComparison.OrdinalIgnoreCase)
@@ -534,7 +532,13 @@ namespace Emby.Server.Implementations.HttpServer
             {
             {
                 var logException = !string.Equals(ex.GetType().Name, "SocketException", StringComparison.OrdinalIgnoreCase);
                 var logException = !string.Equals(ex.GetType().Name, "SocketException", StringComparison.OrdinalIgnoreCase);
 
 
-                await ErrorHandler(ex, httpReq, logException).ConfigureAwait(false);
+                bool ignoreStackTrace =
+                    ex is SocketException
+                    || ex is IOException
+                    || ex is OperationCanceledException
+                    || ex is SecurityException
+                    || ex is FileNotFoundException;
+                await ErrorHandler(ex, httpReq, !ignoreStackTrace, urlToLog).ConfigureAwait(false);
             }
             }
             finally
             finally
             {
             {