From 6f2bfe4d5f3d3ef407d48339b67c909b5e3e72bf Mon Sep 17 00:00:00 2001 From: Louis Somers Date: Wed, 22 Jul 2020 13:45:29 +0200 Subject: [PATCH] Always show errors in the System.Diagnostics.Trace, no matter if they are logged or not. These will show up in the output window of Visual Studio and can be redirected to the console with some configuration. --- .../Errors/UnhandledApiExceptionFilter.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/NetCore/Westwind.Globalization.AspnetCore/Controllers/Errors/UnhandledApiExceptionFilter.cs b/src/NetCore/Westwind.Globalization.AspnetCore/Controllers/Errors/UnhandledApiExceptionFilter.cs index e7cfd734..327c1dd3 100644 --- a/src/NetCore/Westwind.Globalization.AspnetCore/Controllers/Errors/UnhandledApiExceptionFilter.cs +++ b/src/NetCore/Westwind.Globalization.AspnetCore/Controllers/Errors/UnhandledApiExceptionFilter.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Net; -using System.Text; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; @@ -17,6 +14,15 @@ public class UnhandledApiExceptionFilter : ExceptionFilterAttribute public override void OnException(ExceptionContext context) { + // show all exceptions in the Visual Studio output window. + // Can also be redirected to the console with some configuration... + var baseException = context.Exception.GetBaseException(); + System.Diagnostics.Trace.WriteLine(baseException.ToString()); + + // Inner exceptions don't always include the full stacktrace + if (baseException != context.Exception) + System.Diagnostics.Trace.WriteLine(context.Exception.StackTrace); + ApiError apiError = null; if (context.Exception is ApiException) { @@ -39,8 +45,8 @@ public override void OnException(ExceptionContext context) { // Unhandled errors #if !DEBUG - var msg = "An unhandled error occurred."; - string stack = null; + var msg = "An unhandled error occurred."; + string stack = null; #else var msg = context.Exception.GetBaseException().Message; string stack = context.Exception.StackTrace;