diff --git a/Jellyfin.Server/Middleware/ExceptionMiddleware.cs b/Jellyfin.Server/Middleware/ExceptionMiddleware.cs
index 0d9dac89f0..ecc76594e4 100644
--- a/Jellyfin.Server/Middleware/ExceptionMiddleware.cs
+++ b/Jellyfin.Server/Middleware/ExceptionMiddleware.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.Net.Mime;
using System.Threading.Tasks;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
@@ -22,15 +23,15 @@ namespace Jellyfin.Server.Middleware
/// Initializes a new instance of the class.
///
/// Next request delegate.
- /// Instance of the interface.
+ /// Instance of the interface.
/// Instance of the interface.
public ExceptionMiddleware(
RequestDelegate next,
- ILoggerFactory loggerFactory,
+ ILogger logger,
IServerConfigurationManager serverConfigurationManager)
{
_next = next;
- _logger = loggerFactory.CreateLogger();
+ _logger = logger;
_configuration = serverConfigurationManager;
}
@@ -54,9 +55,14 @@ namespace Jellyfin.Server.Middleware
}
ex = GetActualException(ex);
- _logger.LogError(ex, "Error processing request: {0}", ex.Message);
+ _logger.LogError(
+ ex,
+ "Error processing request: {ExceptionMessage}. URL {Method} {Url}. ",
+ ex.Message,
+ context.Request.Method,
+ context.Request.Path);
context.Response.StatusCode = GetStatusCode(ex);
- context.Response.ContentType = "text/plain";
+ context.Response.ContentType = MediaTypeNames.Text.Plain;
var errorContent = NormalizeExceptionMessage(ex.Message);
await context.Response.WriteAsync(errorContent).ConfigureAwait(false);
@@ -105,16 +111,14 @@ namespace Jellyfin.Server.Middleware
}
// Strip any information we don't want to reveal
- msg = msg.Replace(
- _configuration.ApplicationPaths.ProgramSystemPath,
- string.Empty,
- StringComparison.OrdinalIgnoreCase);
- msg = msg.Replace(
- _configuration.ApplicationPaths.ProgramDataPath,
- string.Empty,
- StringComparison.OrdinalIgnoreCase);
-
- return msg;
+ return msg.Replace(
+ _configuration.ApplicationPaths.ProgramSystemPath,
+ string.Empty,
+ StringComparison.OrdinalIgnoreCase)
+ .Replace(
+ _configuration.ApplicationPaths.ProgramDataPath,
+ string.Empty,
+ StringComparison.OrdinalIgnoreCase);
}
}
}