Introduction
Error Logging Modules & Handlers (ELMAH) is a tool for debugging mainly ASP.NET applications as suggested by the wiki. Since we all know there is always a chance of getting exceptions when working on any applications. Handling them is a real challenge for many developers. But if we have a tool then it can provide the details of the exceptions or errors with the stack trace as well. Apart from showing the users the Yellow screen of death, we show the users a customized error page and for the developers if an exception occurs then instead of a try/catch block for every method, ELMAH provides them the details of the exceptions with the entire stack trace and a solution based on the error code. For more information on error codes and redirection please follow one of my other articles Custom Errors. Let's get into more details of how this beautiful tool works.
What we get
You would be wondering what this ELMAH gives us after adding this into the application. Straight from the Hanselmen's blog, ELMAH would provide us the following without changing a single peice of code. Since ELMAH includes modules and handlers, it greatly supports HttpModules and Http Handlers.
- All unhandled exceptions (null references, out of bound exceptions and so on) are logged in the ELMAH interface.
- A webpage can remotely view the logged detailed exceptions.
- Since this shows the entire stack trace, the so-called Yellow screen of death can also be seen but in the ELMAH interface.
- ELMAH also provides an opportunity to store the exceptions or log them into tables (SSMS).
- <customerrors mode="On" defaultredirect="/Default/Error">
- <error statuscode="404" redirect="/Default/NotfoundError">
- </error></customerrors>
Suppose the preceding is the case and the user using the application lands on the preceding redirect path URL pages, whereas the error and exception are managed by ELMAH and mailed or logged into the database for future reference for the developers.
Installation for an existing MVC project
Step 1
Go to references and right-click on the Manage Nuget Packages.
Step 2
Search online for Elmah.MVC.
Step 3
After the successful installation, you can check the package.config for the version of ELMAH installed as shown below:
Step 4
You need to ensure the following web.config configurations as shown in the images below:
- <sectionGroup name="elmah">
- <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
- <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
- <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
- <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
- </sectionGroup>



Abhishek MaitreyPosted Feb 9, 2015, 7:31 AM
nicely explained Suraj. I'll read it's second part too. twitter:@abhimaitrey
Vithal WadjePosted Feb 8, 2015, 6:52 AM
nice