Remove old UnhandedExceptionLoggerConfigurationAttribute and UnhandledExceptionLogger
This commit is contained in:
@@ -237,8 +237,6 @@
|
||||
<Compile Include="WebApi\Filters\FeatureAuthorizeAttribute.cs" />
|
||||
<Compile Include="WebApi\SessionHttpControllerRouteHandler.cs" />
|
||||
<Compile Include="WebApi\UmbracoApiControllerTypeCollectionBuilder.cs" />
|
||||
<Compile Include="WebApi\UnhandedExceptionLoggerConfigurationAttribute.cs" />
|
||||
<Compile Include="WebApi\UnhandledExceptionLogger.cs" />
|
||||
<Compile Include="Runtime\WebInitialComponent.cs" />
|
||||
<Compile Include="Mvc\ControllerContextExtensions.cs" />
|
||||
<Compile Include="Mvc\DisableBrowserCacheAttribute.cs" />
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Umbraco.Web.WebApi
|
||||
[DisableBrowserCache]
|
||||
// [UmbracoWebApiRequireHttps]
|
||||
// [CheckIfUserTicketDataIsStale]
|
||||
[UnhandedExceptionLoggerConfiguration]
|
||||
// [UnhandedExceptionLoggerConfiguration]
|
||||
[EnableDetailedErrors]
|
||||
public abstract class UmbracoAuthorizedApiController : UmbracoApiController
|
||||
{
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.ExceptionHandling;
|
||||
using System.Web.Http.Filters;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Web.WebApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds our unhandled exception logger to the controller's services
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Important to note that the <see cref="UnhandledExceptionLogger"/> will only be called if the controller has an ExceptionFilter applied
|
||||
/// to it, so to kill two birds with one stone, this class inherits from ExceptionFilterAttribute purely to force webapi to use the
|
||||
/// IExceptionLogger (strange)
|
||||
/// </remarks>
|
||||
public class UnhandedExceptionLoggerConfigurationAttribute : ExceptionFilterAttribute, IControllerConfiguration
|
||||
{
|
||||
public virtual void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
|
||||
{
|
||||
controllerSettings.Services.Add(typeof(IExceptionLogger), new UnhandledExceptionLogger());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Web.Http.ExceptionHandling;
|
||||
using Umbraco.Web.Composing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Umbraco.Web.WebApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to log unhandled exceptions in webapi controllers
|
||||
/// </summary>
|
||||
public class UnhandledExceptionLogger : ExceptionLogger
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public UnhandledExceptionLogger()
|
||||
: this(Current.Logger)
|
||||
{
|
||||
}
|
||||
|
||||
public UnhandledExceptionLogger(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override void Log(ExceptionLoggerContext context)
|
||||
{
|
||||
if (context != null && context.Exception != null)
|
||||
{
|
||||
var requestUrl = context.ExceptionContext?.ControllerContext?.Request?.RequestUri?.AbsoluteUri;
|
||||
var controllerType = context.ExceptionContext?.ActionContext?.ControllerContext?.Controller?.GetType();
|
||||
|
||||
_logger.LogError(context.Exception, "Unhandled controller exception occurred for request '{RequestUrl}'", requestUrl);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user