Is there an easy way to log all exceptions in an ASP.NET application? I'm already logging unhandled exceptions through the Application_OnError event, but I want to perform logging even when an exception is handled on a page level.
Many thanks.
Today there's no easy way in Web API to log or handle errors globally. Some unhandled exceptions can be processed via exception filters, but there are a number of cases that exception filters can't handle. For example: Exceptions thrown from controller constructors.
Exception class. An exception is thrown from an area of code where a problem has occurred. The exception is passed up the call stack to a place where the application provides code to handle the exception. If the application does not handle the exception, the browser is forced to display the error details.
The LogException (Exception, String, String, Boolean) method logs an exception with information about the calling method, when the exception occurred, and whether the exception was caught and handled.
Error handling in ASP.NET has three aspects: Tracing - tracing the program execution at page level or application level. Error handling - handling standard errors or custom errors at page level or application level. Debugging - stepping through the program, setting break points to analyze the code.
You could use Elmah to log your exceptions. It's really easy to use and gives good information about the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With