diff --git a/Oqtane.Server/Infrastructure/Middleware/ExceptionMiddleware.cs b/Oqtane.Server/Infrastructure/Middleware/ExceptionMiddleware.cs index d8ef15c1..5a25f9a7 100644 --- a/Oqtane.Server/Infrastructure/Middleware/ExceptionMiddleware.cs +++ b/Oqtane.Server/Infrastructure/Middleware/ExceptionMiddleware.cs @@ -1,11 +1,10 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Oqtane.Enums; -using Oqtane.Models; +using Oqtane.Extensions; using Oqtane.Shared; namespace Oqtane.Infrastructure @@ -27,18 +26,18 @@ namespace Oqtane.Infrastructure } catch (Exception exception) { - var _logger = provider.GetRequiredService(); var endPoint = context.GetEndpoint()?.DisplayName; - var contextAlias = context.Items.FirstOrDefault(i => i.Key.ToString() == "Alias"); - Alias alias; - int siteId = -1; - var defaultVal = default(KeyValuePair); - if (!contextAlias.Equals(defaultVal)) + var alias = context.GetAlias(); + if (alias != null) { - alias = contextAlias.Value as Alias; - siteId = alias.SiteId; + var _logger = provider.GetRequiredService(); + _logger.Log(alias.SiteId, Shared.LogLevel.Error, this, LogFunction.Other, exception, "Unhandled Exception: {Error} For Endpoint: {Endpoint}", exception.Message, endPoint); + } + else + { + var _filelogger = provider.GetRequiredService>(); + _filelogger.LogError(Utilities.LogMessage(this, $"Endpoint: {endPoint} Unhandled Exception: {exception}")); } - _logger.Log(siteId, LogLevel.Error, endPoint, LogFunction.Other, exception, exception.Message, context.User?.Identity.Name); } } }