Let’s first establish what the purpose of the code is. For this article, the purpose of code is to learn about ELMAH and how to use and configure it in MVC.
What is ELMAH?
ELMAH stands for Error Logging Modules And Handlers that provide functionality to logging runtime ASP.NET errors.
Why do we choose ELMAH?
- ELMAH enables logging of all unhandled exceptions.
- ELMAH logs all errors in many storages, like - SQL Server, MySQL, Randon Access Memory (RAM), SQL Lite, and Oracle.
- ELMAH has functionality to download all errors in CSV file.
- RSS feed for the last 15 errors
- Get all error data in JSON or XML format
- Get all errors to our mailbox
- Send error log notification to your application
- Customize the error log by custiomizing some code
ELMAH HTTP Modules
There are three HTTP Modules.
- ErrorMailModule
ErrorMailModule is used for sending the details of log as an email. - ErrorLogModule
ErrorLogModule is used for logging all the exceptions and some other details, like IP- Address, Usersname, Website Username etc. - ErrorFilterModule
ErrorFilterModule is used to customize the exception logs.
How to use ELMAH?
Step 1
Create a new MVC application.
- On the File menu, click New >> Project.
- In the New Project dialog box, under Project types, expand "Visual C#", and then click "Web" and in the Name box, type "DemoELMAH". Finally, click on OK.
- Now, In the dialog box, click on "MVC" under ASP.NET 4.5.2 Templates. Then, click on "Change Authentication" which stays on the center of the right side. Then, select "No Authentication" and click on OK.
Step 2
Install ELMAH Library and register its modules.
- Open NuGet Package Manager Console -
Click on Tools > NuGet Package Manager > Package Manager Console.
- Type "Install-Package elmah" and hit Enter.
- After successful installation, you will find the below screen.

- ELMAH Modules are default registered in web.config. If not, then use the below code.
- <system.web>
- <compilation debug="true" targetFramework="4.5.2" />
- <httpRuntime targetFramework="4.5.2" />
- <httpModules>
- <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
- <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
- <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" /> </httpModules>
- </system.web>
- <system.webServer>
- <modules>
- <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
- <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
- <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" /> </modules>
- </system.webServer>
- <elmah>
- <security allowRemoteAccess="false" /> </elmah>
- <location path="elmah.axd" inheritInChildApplications="false">
- <system.web>
- <httpHandlers>
- <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" /> </httpHandlers>
- </system.web>
- <system.webServer>
- <handlers>
- <add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" /> </handlers>
- </system.webServer>
- </location>// This is just a sample script. Paste your real code (javascript or HTML) here. if ('this_is'==/an_example/){of_beautifier();}else{var a=b?(c%d):e[f];}
- Create an ActionMethod.
Run the Project. Now, enter the wrong URL in address bar and hit Enter. We will get 404 Error.- public ActionResult Index() {
- return View();
- }

Now, for ELMAH Log, enter the below URL in address bar.
http://localhost:57979/elmah.axd

NOTE - MVC now ignores .axd files by default. So, this one is not used in Server. But later in this article, we will store the logs in another location.
Step 3
Setup Mail Server for getting every log in email; add the below code in web.config.
- <elmah>
- <errorMail from="****@elmah.com" to="***.***@gmail.com" subject="Error - ELMAH demo - ***" async="true" /> </elmah>
- <system.net>
- <mailSettings>
- <smtp deliveryMethod="Network">
- <network host="host address" port="port number" userName="your username" password="your password" /> </smtp>
- </mailSettings>
- </system.net>
Store ELMAH logs on different locations.
- Store ELMAH logs in XML file
Create one folder named "ElmahLog" in root directory of your project. We use this folder for saving the XML file.
Add the below setting in your Web.config.
- <elmah>
- <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/ElmahLog" /> </elmah>
- Store ELMAH logs in RAM.
Add the below setting in your Web.config.
- <elmah>
- <errorLog type="Elmah.MemoryErrorLog, Elmah" size="100" /> </elmah>
- Store ELMAH logs in Microsoft SQL Server.
Add the below setting in your Web.config.
Note- <elmah>
- <errorLog type="Elmah.SqlErrorLog, Elmah" connectionString="DBEntities" /> </elmah>
Don`t forgot to add connectionString name as "DBEntities".
- <connectionStrings>
- <add name="DBEntities" connectionString="data source=server name;initial catalog=database name;persist security info=True;user id=your username;password=your password;Trusted_Connection=True" /> </connectionStrings>
All Done.. :)

Ankit KanojiaPosted Mar 12, 2020, 2:30 AM
And yes, Thank you Nabil for being interactive as well.
Ankit KanojiaPosted Mar 12, 2020, 2:30 AM
And still you can not get what i mean you can google it, you'll definitely get the resolution for sure.
Ankit KanojiaPosted Mar 12, 2020, 2:29 AM
Nabil Nawaz: the issue which you mentioned it can be resolved only just putting more fields with assigning custom object and then stringify that object to elmah response.
Ankit KanojiaPosted Mar 12, 2020, 2:27 AM
There are also other feartures with the elmah when you go through elmah community. So you can use those as well.
Ankit KanojiaPosted Mar 12, 2020, 2:26 AM
Parth Mehta : there are many more features with new version, will share those featured article soon.
Ankit KanojiaPosted Mar 12, 2020, 2:25 AM
Nabil Nawaz : i will work on it and make it much better than previous one fpr sure. will share you once it completed. Thank you
Ankit KanojiaPosted Mar 12, 2020, 2:24 AM
Thank you so much Prafulla Sahu
Ankit KanojiaPosted Mar 12, 2020, 2:24 AM
Thank you so much Nabil Nawaz
Ankit KanojiaPosted Mar 12, 2020, 2:24 AM
Thank you so much Parth Mehta
Ankit KanojiaPosted Mar 12, 2020, 2:23 AM
Thank you so much Manav Pandya
Prafulla SahuPosted Mar 20, 2019, 5:35 AM
This is what I was Exactly Looking for. Thanks Suchit
Nabil NawazPosted Jan 9, 2017, 12:56 AM
Thank you for this article.. can you tell more about it ? how can i customize it to add & show more fields on error log page ?
Parth MehtaPosted Jan 1, 2017, 9:49 AM
Thanks Suchit. features are summarize in good way.
Manav PandyaPosted Dec 8, 2016, 4:33 AM
Thanks for that im looking for that Suchit Khunt sir