简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM