EPiServer CMS 6 with ELMAH
This blog post is about integrating EPiServer CMS 6 with ELMAH. ELMAH provides functionality to log and view unhandled exceptions that occur on a website. We’’ll use the EPiServer CMS 6 dashboard with an RSS gadget to consume the ELMAH RSS feed.
ELMAH (Error Logging Modules and Handlers) is a pluggable error logging facility that can be added to any ASP.NET application. The beauty of it is that no recompilation is necessary. Simply tweak web.config and add the binaries to the bin folder and you’re good to go!
Just because your website has gone into production it does not necessarily mean that it will be bug-free. Recreating errors that users experience are not always an easy task. ELMAH records all unhandled errors that occur on the website. By clicking the details link we get a more detailed view of the error.
These errors can then be viewed through an HTTP handler, RSS feed or ELMAH can mail you when the error occurs.
The alternative would be to use log4net. But you need add logic to global.asax or write your own error-logging module. I advocate using log4net to keep track of events (info, debug, warnings, errors) you know can occur. ELMAH is for the twilight zone where things go bump.
Installing ELMAH is very straightforward. Copy the binaries to your bin folder and modify web.config accordingly. It’s also easy to restrict access to the ELMAH handler.
Here’s how web.config should look.
First the handlers section.
<add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" preCondition="integratedMode" type="Elmah.ErrorLogPageFactory, Elmah"/>
Then the modules section.
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
ELMAH RSS feed
I’m a fan of the EPiServer CMS 6 online center with the gadgets dashboard. Here we can create a central hub for web editors and administrators to monitor their site. To keep it simple we’ll just add an RSS reader for the ELMAH RSS feed.
But… there’s a snag. ELMAH uses RSS version 0.91. This is not compatible with the RSS feed reader in EPiServer CMS 6. You’ll end up with an error like this.
I simply modified the ELMAH source code to specify the RSS version as 2.0 instead. You can download the fix here (x64 release).