C# PROGRAMMING
This article shows how to set up logging using ELMAH.
ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.
Once ELMAH has been dropped into a running web application and configured appropriately, you get the following facilities without changing a single line of your code:
- Logging of nearly all unhandled exceptions.
- A web page to remotely view the entire log of recorded exceptions.
- A web page to remotely view the full details of anyone logged exception, including colored stack traces.
- In many cases, you can review the original yellow screen of death that ASP.NET generated for a given exception, even with customErrors mode turned on.
- An e-mail notification of each error at the time it occurs.
- An RSS feed of the last 15 errors from the log.
How to add logging?
Install nuget package into ASP.NET Web Forms application as shown below
![](https://cdn-images-1.medium.com/max/800/1*ZWewDfyxGy3dliRzFJD8PA.png)
After installation is complete, few lines of code will be added into web.config file as shown below
https://gist.github.com/ssukhpinder/3e7e73d5102cde2982a8b4462abc0c96
Github Sample
https://github.com/ssukhpinder/LoggingExampleASP.NET
Demo
![](https://cdn-images-1.medium.com/max/800/1*tPV-5MKWpuyF6OR4X2yejg.gif)
In above sample, we deliberately added divide by zero exception in “About.aspx” to show unhandled exception using ELMAH.
Step 1: Ctrl + F5 to run the application locally.
Step 2: Application will generate unhandled exception when route to “About” page as shown below
![](https://cdn-images-1.medium.com/max/800/1*fTrfcWD0HwuIwZy4_mWQ8g.png)
Step 3: Open another tab & redirect to https://localhost:44369/elmah.axd (NOTE that port no may vary) and generated exception will be shown as below
![](https://cdn-images-1.medium.com/max/800/1*7Uzv2ztiGeaRYd0l7OW3YA.png)
User view each exception details & export them into log file as well.
For more technical articles on angular & other languages: