From 3615db6986af2305cd8e59c3dd2f1c2910ec6b22 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Thu, 28 Feb 2019 22:33:18 +0100 Subject: [PATCH] No longer rely on HttpContext.AddError to forward Web API exceptions to SerilogWeb module Instead rely on ad-hoc extension method that stores it temporarily in HttpContext Related to #16 and #3 --- .../Classic/WebApi/WebApiExceptionLogger.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SerilogWeb.Classic.WebApi/Classic/WebApi/WebApiExceptionLogger.cs b/src/SerilogWeb.Classic.WebApi/Classic/WebApi/WebApiExceptionLogger.cs index 59345b1..1742325 100644 --- a/src/SerilogWeb.Classic.WebApi/Classic/WebApi/WebApiExceptionLogger.cs +++ b/src/SerilogWeb.Classic.WebApi/Classic/WebApi/WebApiExceptionLogger.cs @@ -1,5 +1,6 @@ using System.Web; using System.Web.Http.ExceptionHandling; +using SerilogWeb.Classic.Extensions; namespace SerilogWeb.Classic.WebApi { @@ -7,7 +8,10 @@ public class WebApiExceptionLogger : ExceptionLogger { public override void Log(ExceptionLoggerContext context) { - HttpContext.Current.AddError(context.Exception); + if (context.Exception != null) + { + HttpContext.Current.AddSerilogWebError(context.Exception); + } } } } \ No newline at end of file