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
You could use Elmah to log your exceptions. It's really easy to use and gives good information about the problem.
I don't think there is anyway of automatically logging handled exceptions. If you're already doing the Application_OnError logging for unhandled exceptions I'm afraid that Colin's correct and you're going to have to call your logging component in the catch blocks for the handled exceptions you want logging for.
Call your logging component in the catch blocks for exceptions that are handled.
ASP.NET Health Monitoring does this in an elegant and fairly automatic way (no need to manually catch exceptions):
When you click the first link, there is an example of how to enable and configure ASP.NET Health Monitoring. You need to configure it in web.config file.
For logging to a DB, you can create the corresponsing table using the ASP.NET SQL Server Registration Tool: ASP.NET SQL Server Registration Tool (Aspnet_regsql.exe)
I really like it. For manual logging, patterns & practices Enterprise Library's Logging Application Block might be something for you, but this is slightly off-topic.
Matthias
I agree with Collin, that you should log wherever you catch (and don't rethrow).
But if you need that every exception logged without much code modifications, then handle the AppDomain.FirstChanceException Event, and you'll get ALL the exceptions (maybe that's even too much :p, but it could help you clean the code).
Assuming you are only throwing and catching your own exception-types (derived from System.Exception ofc), you could make your base-exception log whatever you need in its constructor.