Programming Microsoft ASP.NET 4 - Dino Esposito [151]
A tool that is popular among ASP.NET developers is Error Logging Modules And Handlers (ELMAH). ELMAH is essentially made of an HTTP module that, once configured, intercepts the Error event at the application level and logs it according to the configuration to a number of back-end repositories. ELMAH comes out of an open-source project (http://code.google.com/p/elmah) and includes a number of extensions, mostly in the area of repositories. ELMAH offers some nice facilities, such as a Web page to view all recorded exceptions and drill down into each of them. Any error reporting system specifically designed for ASP.NET can’t be, architecturally speaking, much different from ELMAH.
Note
You might want to take a look at some commercial products that offer a reporting mechanism for ASP.NET applications. One of these products is Red Gate’s SmartAssembly (http://www.red-gate.com/products/smartassembly/error_reporting.htm). Although it’s not specifically designed for ASP.NET, the tool can be easily adapted to add reporting capabilities to ASP.NET applications. Essentially, it takes an existing assembly and parses its compiled code adding try/catch blocks that log any possible exceptions and upload the complete information to a given Web site. The tool also has a desktop front end to help you navigate through logged exceptions.
Self-Logging Exceptions
Another handmade solution consists of employing custom exception classes that derive from a user-defined class endowed with the ability to log automatically. In this way, at the cost of using custom exceptions everywhere, you can log any exceptions you’re interested in regardless of whether the exception is fatal or not.
Debugging Options
Debugging an ASP.NET page is possible only if the page is compiled in debug mode. An assembly compiled in debug mode incorporates additional information for a debugger tool to step through the code. You can enable debug mode on individual pages as well as for all the pages in a given application. The <% @Page Debug="true" %> ASP.NET compiles the contents of any .aspx resource before execution. The contents of the .aspx resource is parsed to obtain a C# (or Microsoft Visual Basic .NET) class file, which is then handed out to the language compiler. When a page is flagged with the Debug attribute, ASP.NET doesn’t delete the temporary class file used to generate the page assembly. This file is available on the Web server for you to peruse and investigate. The file is located under the Windows folder at the following path: Microsoft.NET\Framework\[version]\Temporary ASP.NET Files. Debug mode is important for testing applications and diagnosing their problems. Note, though, that running applications in debug mode has a significant performance overhead. You should make sure that an application has debugging disabled before deploying it on a production server. In ASP.NET 4 and Visual Studio 2010,