elmah2

Few days ago I’ve noticed that “error.aspx” becomes quite popular destination on my site. What’s going on? I never run into errors, how do I know what others do to break in? Elmah to the rescue! This little utility specifically designed to run in the background and record any ASP.NET errors so you can review them later at your convenience. If you interested how it all works, check out this excellent article on MSDN, it goes in depth explaining technical details. I’ll focus here on how to set it up with BlogEngine (or any ASP.NET web forms application to that matter).

First, go get latest binaries from the project site. Unzip and move Elmah.dll to “bin” folder on your site. There are several versions included with download, for BE 1.5 I’m using Elmah\bin\net-2.0\Release\Elmah.dll.

Once you have DLL in the “bin” folder, you need to set up your application to use it. With download comes sample site, it has web.config with examples on how to use Elmah with different configurations (Elmah\samples\web.config). You can set it up to record errors to XML files or number of databases, including SQL server, VistaDB etc. I’m using XML data provider, so I’ll set it up to dump all errors to ~/app_data/elmah.

<configuration>
 
    <configSections>
        <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"/>
            <section name="errorTweet" requirePermission="false" type="Elmah.ErrorTweetSectionHandler, Elmah"/>
        </sectionGroup>
    </configSections>
 
    <elmah>  
        <security allowRemoteAccess="yes" />
        <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="C:\inetpub\wwwroot\blog\app_data\elmah" />
    </elmah>
 
    <system.web>
        <httpModules>   
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
        </httpModules>
        <httpHandlers>
            <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
        </httpHandlers>
    </system.web>
 
    <!-- IIS 7 -->
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <modules>
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
        </modules>
        <handlers>
            <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
        </handlers>
    </system.webServer>
 
    <location path="elmah.axd">
        <system.web>
            <authorization>
                <deny users="?"/>
            </authorization>
        </system.web>
    </location>
 
</configuration>

As you can see, there are just few things you need to add to configuration to get Elmah started. With this in place, you’ll be able navigate to elmah.axd and see list of errors happened within your application and recorded by Elmah. This includes yellow screen of death and all server variables at the moment error occurred. Very helpful! In my case, it turned out that empty user profile caused Foaf handler to throw an error. Added a null check to condition, and 99% errors went away, no more worries.

elmah

If you find it useful, you can extend Elmah to be much smarter, save errors to database, purge after period of time, send email notifications and even twit your errors to the world (no, I’m not trying to be funny – it really has twitter provider).

Share/Save/Bookmark
Signature

Comments

10/27/2009 2:15:16 AM #

Ben Amada

Good tip.  I think it's good we now have error.aspx in BE as a graceful way to handle/present unhandled exceptions.  I should check my logs to see how often "error.aspx" might be popping up.

Ben Amada |

11/27/2009 8:38:45 AM #

Nicholas

Great, I don't like having errors on my sites, this is very helpful

Nicholas |

12/3/2009 6:26:53 AM #

Bedding Duvet Covers

Thanks for the article, i will try to implement Elmah with my blogengine site.

Bedding Duvet Covers |

1/29/2010 6:35:04 AM #

Hyomin

Great fixed! I was looking for this too.
Thanks for saving my time a lot!

Smile

Hyomin |

2/12/2010 2:38:51 PM #

trackback

BlogEngine.NET 1.6 Breaking Old Links

BlogEngine.NET 1.6 Breaking Old Links

LavaBlast Software Blog |

3/2/2010 11:43:25 PM #

Pravesh

Great, Thanks for sharing. Helped me to fix errors on my blog.

Pravesh |

Comments are closed