Installation
Elmah is error logging third party library which you can add to ASP.NET application to enable capture of almost all errors.
You can add this to your project in about a minute by using the very cool tool NuGet. http://nuget.codeplex.com/
I discussed this briefly in this post “NuGet, the new way to get third party dlls into your application”.
You can find Elmah here: http://code.google.com/p/elmah/
Storing Errors into the database
Once you have added the package, you will probably want to configure Elmah to store the error data into persistent data storage. I have chosen SQL Server as the application already uses this for other data.
The first task is to download the DDL script to create the tables in the database where the errors will be stored. You can find this here: http://code.google.com/p/elmah/wiki/Downloads?tm=2
Next, add the following lines below the <configSections> node in the web.config file
<elmah>
<security allowRemoteAccess="yes" />
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="[your connection string name here]" />
</elmah>
You can test this by entering an aspx url on your server which does not exist. You can then view the error log at http://yourwebsite/elmah.axd
Securing Elmah
All well and good but now anyone can view the errors and potentially gain information they can use to hack your site. So here’s how to secure your Elmah.axd
First, you can add the admin path to the httpHandler section:
<httpHandlers>
<add verb="POST,GET,HEAD" path="/admin/elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
Next you can add a location element to the web.config to restrict access to the axd. Like this:
<!-- Deny unauthenticated users to see the elmah.axd --><location path="admin"><system.web><authorization><deny users="?"/></authorization></system.web></location>
This last part has been taken directly from here
Now only authenticated users have access to the file.
References
http://msdn.microsoft.com/en-us/library/aa479332.aspx
http://code.google.com/p/elmah/
http://dotnetslackers.com/articles/aspnet/ErrorLoggingModulesAndHandlers.aspx
http://naspinski.net/post/Installing-ELMAH-for-simple-error-logging.aspx
http://haacked.com/archive/2007/07/24/securely-implement-elmah-for-plug-and-play-error-logging.aspx