From 9e5fda6c42aa2e3d12e27bff3c17ddbd811d8da7 Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 13 Oct 2020 13:05:08 +0200 Subject: [PATCH] Remove old UnhandedExceptionLoggerConfigurationAttribute and UnhandledExceptionLogger --- src/Umbraco.Web/Umbraco.Web.csproj | 2 -- .../WebApi/UmbracoAuthorizedApiController.cs | 2 +- ...edExceptionLoggerConfigurationAttribute.cs | 29 --------------- .../WebApi/UnhandledExceptionLogger.cs | 36 ------------------- 4 files changed, 1 insertion(+), 68 deletions(-) delete mode 100644 src/Umbraco.Web/WebApi/UnhandedExceptionLoggerConfigurationAttribute.cs delete mode 100644 src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 5f934c2359..5f6ce7fc84 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -237,8 +237,6 @@ - - diff --git a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs index 2851d5e24f..993fd36bc2 100644 --- a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs @@ -26,7 +26,7 @@ namespace Umbraco.Web.WebApi [DisableBrowserCache] // [UmbracoWebApiRequireHttps] // [CheckIfUserTicketDataIsStale] - [UnhandedExceptionLoggerConfiguration] + // [UnhandedExceptionLoggerConfiguration] [EnableDetailedErrors] public abstract class UmbracoAuthorizedApiController : UmbracoApiController { diff --git a/src/Umbraco.Web/WebApi/UnhandedExceptionLoggerConfigurationAttribute.cs b/src/Umbraco.Web/WebApi/UnhandedExceptionLoggerConfigurationAttribute.cs deleted file mode 100644 index 6dc1a49eb1..0000000000 --- a/src/Umbraco.Web/WebApi/UnhandedExceptionLoggerConfigurationAttribute.cs +++ /dev/null @@ -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 -{ - /// - /// Adds our unhandled exception logger to the controller's services - /// - /// - /// Important to note that the 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) - /// - public class UnhandedExceptionLoggerConfigurationAttribute : ExceptionFilterAttribute, IControllerConfiguration - { - public virtual void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor) - { - controllerSettings.Services.Add(typeof(IExceptionLogger), new UnhandledExceptionLogger()); - } - - } -} diff --git a/src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs b/src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs deleted file mode 100644 index 903e333846..0000000000 --- a/src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Web.Http.ExceptionHandling; -using Umbraco.Web.Composing; -using Microsoft.Extensions.Logging; - -namespace Umbraco.Web.WebApi -{ - /// - /// Used to log unhandled exceptions in webapi controllers - /// - 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); - } - } - - } -}