Merge pull request #3929 from sbwalker/dev

modifications to ExceptionMiddleware
This commit is contained in:
Shaun Walker 2024-03-01 16:14:44 -05:00 committed by GitHub
commit 9a05f659f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<ILogManager>();
var endPoint = context.GetEndpoint()?.DisplayName;
var contextAlias = context.Items.FirstOrDefault(i => i.Key.ToString() == "Alias");
Alias alias;
int siteId = -1;
var defaultVal = default(KeyValuePair<int, string>);
if (!contextAlias.Equals(defaultVal))
var alias = context.GetAlias();
if (alias != null)
{
alias = contextAlias.Value as Alias;
siteId = alias.SiteId;
var _logger = provider.GetRequiredService<ILogManager>();
_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<ILogger<ExceptionMiddleware>>();
_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);
}
}
}