Mrinal Kamboj
Mrinal Kamboj

Reputation: 11482

ASP.Net Web API exception filter, logging to database failing

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

Upvotes: 1

Views: 708

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038730

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.

Upvotes: 2

Related Questions