1

In our ASP.Net Web API application we are planning to handle the handle exceptions via Global exception filter attribute, as detailed in the following link.

We are planning to log the exception to in multiple medium like database, files using NLog. what baffles me is a medium like Database, if we log and there's an exception like database down, connection timeout and multiple others, then it will go in infinite loop, as it will keep try to log the exception, which will be keep returning an exception.

Is there a mechanism to restrict it 1 or 2 tries and after that fail silently, not enter an infinite loop, any pointers

1 Answer 1

2

We are planning to log the exception to in multiple medium like database, files using NLog. what baffles me is a medium like Database, if we log and there's an exception like database down, connection timeout and multiple others, then it will go in infinite loop, as it will keep try to log the exception, which will be keep returning an exception.

That's why you should make absolutely sure that your logging code never fails. For example by wrapping it in a try/catch statement.

Sign up to request clarification or add additional context in comments.

2 Comments

If I am using Exception Filter, do I have the provision to use a Try Catch block, since I am overriding an OnException method which automatically gets triggered on exception, until and unless I start checking the specific error messages, I cannot stop that looping. There could be hundred of such messages, what's the way out
does your message means that in OnException override method, I include the logging inside a Try Catch and this would take care of exception in that part, will not reinvoke the OnException call as I am expecting

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.