4

I am trying to catch errors from my .NET application before they are written to the event log. I have seen in the accepted answer to this question that the way to do it would be to include an Application_Error (or Application_OnError it says) function in the Global.asax.

However, we have switched to using Startup.cs only now, and can't work out how to make the equivalent call. The accepted answer to this question suggests that it may not be possible. Does anyone know for sure if there is an equivalent way to handle these errors?

1

1 Answer 1

6

By saying you've "switched to using Startup" I'm assuming you mean using an OWIN pipeline.

Application_Error only gets called when an exception is thrown during a request, and is unhandled.

So the equivalent in an OWIN pipeline is to catch any unhandled exceptions at the start of your OWIN pipeline.

In other words you need to create a custom middle-ware with a try/catch around the call to _next and then you can do what you want with the exception in the catch clause.

This other StackOverlow answer shows how it is done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.