Integrating ELMAH with Umbraco
Update: For the latest details on how to integrate ELMAH with Umbraco, please read the article over on the Our Umbraco wiki.
I have a few Umbraco projects that have a lot of custom .NET code, mostly in they are in the form of user-controls and XSLT extensions. As far as I’m aware Umbraco doesn’t have an extendable mechanism for exception handling and sending out notification emails, (there is the umbraco.BusinessLogic.Log, which writes to the umbracoLog table in the database, but that’s all).
Initially I looked at Tim Gaunt’s Advanced Error Reporting – a great drop-in solution that does exactly what it says on the tin! Whilst reading the comments on Tim’s blog, Simon Dingley reminded me of the ELMAH project – which has been one of those web-applications that you keep meaning to try out, but never get around to.
What is 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.
So I decided to see how nicely it plays with Umbraco… the result, it plays very nicely indeed.
If you are interested, here’s how…
- Download the latest ELMAH binary release (1.0 Beta 3 at the time of writing [direct link]) from the Google Code project page. (http://code.google.com/p/elmah/)
- Extract the files from the ZIP.
- Select the DLLs from the “
/bin/” folder, for Umbraco you’ll be using the DLL from “/bin/net-2.0/Release/“. For the benefit of this post, I decided to use the SQLite option to store the error logs in a database. I could easily have used the SQL Server or VistaDB options. - Drop the DLLs into the “
/bin/” folder of your Umbraco installation. - Open the web.config of your Umbracoo installation and add the following lines:
Add the following to your <configSections> section:
<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"/> </sectionGroup>
Add the following just after the </configSections> section:
<elmah> <security allowRemoteAccess="yes" /> <errorLog type="Elmah.SQLiteErrorLog, Elmah" connectionStringName="ELMAH.SQLite" /> <errorMail from="no-reply@domain.com" to="webmaster@domain.com" /> </elmah>
Add the following to your <connectionStrings> section, (if you have one, otherwise create one):
<add name="ELMAH.SQLite" connectionString="Data Source=~/data/errors.s3db"/>
In the <httpModules> section, add this:
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/> <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
… and finally, in the <httpHandlers> section, add this:
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
If you run into any trouble, there is a more detailed guide on Setting Up ELMAH from DotNetSlackers.
By now you should have ELMAH up and running. Open up your web-browser and go to http://localhost/elmah.axd, (obviously replace “localhost” with whatever your hostname is). You should see the ELMAH Error Log page. Since this is open to the public, you may want to secure it, see the Securing Error Log Pages article for further details.
The last part is to integrate the ELMAH Error Log page into the Umbraco back-end. I created a new user-control in the “/usercontrols/” folder called “ELMAH.ascx”, using the following HTML:
<%@ Control Language="C#" %> <iframe height="98%" width="100%" scrolling="auto" src="elmah.axd" style="margin-top:5px;"></iframe>
Then in the “/config/Dashboard.config” configuration file, I added a new section for the developer area.
<section> <areas> <area>developer</area> </areas> <tab caption="Error Logging Modules and Handlers for ASP.NET"> <control>/usercontrols/ELMAH.ascx</control> </tab> </section>
Now in the Umbraco back-end the developer area looks like this.
I have been very impressed with how well ELMAH functions. Aside from the essential email notifications, the RSS feeds are a great bonus!




Nice article. Thanks for sharing!
Kenneth Solberg
April 24, 2009 at 6:58 am
Great article Lee,
Now I should try that out as well, having a bunch of .net controls as well…
Thanks for sharing.
/Dirk
Dirk
April 24, 2009 at 7:58 am
This is great,
Far more easy to integrate as a Log4Net or other framework. And you can actually see the error reports. Great thanks for sharing.
Richard
Richard
April 24, 2009 at 8:38 am
Works great, small issue when installing on x64 server. Needs other SQLLite assembly
Tim Geyssens
April 24, 2009 at 3:26 pm
Great stuff Lee, worked a treat for me.
Simon Dingley
April 28, 2009 at 2:40 pm
Nice one Lee! I tried this after seeing your tweet the other week and it worked great. I had to update the path to include a leading slash, i.e. “/elmah.axd” instead of “elmah.axd”. I used SQL Server too, and to change the compatibility level I needed to use the stored procedure (rather than the command included in the instructions on the Elmah site):
EXEC sp_dbcmptlevel MY_DATABASE, 80;
It runs like a dream and you can flag your own error messages to it for debugging – I’ll definitely be using this for every site from now on. Thanks for the tip on the user control for Umbraco’s admin back-end – I hadn’t thought of that bit!
David
David Conlisk
May 8, 2009 at 1:42 pm
[...] a comment » Following on from Lee Kelleher’s excellent post on integrating ELMAH into Umbraco I have managed to plug in log4Net. This technique could also be used to plugin anything else that [...]
Integrating log4net into Umbraco site. « Ismail’s umbraco adventures
May 19, 2009 at 4:21 pm
Lee,
Just found this about sending elmah logs via Gmail http://scottonwriting.net/sowblog/posts/13845.aspx could be of interest.
Regards
Ismail
ismailmayat
May 22, 2009 at 3:36 pm
Superb!! It works like a charm.
Mario Allegro
May 25, 2009 at 9:52 am
Hello Everybody,
I was just curious if any body has tried integrating ELMAH with MySql, i am trying for the implementation but stuck at the moment.
Rajiv
June 8, 2009 at 4:06 am
Hi Rajiv,
Thanks for your comment, I see that you have been liaising with Atif (the core ELMAH developer) about it – that’s probably your best bet.
http://groups.google.com/group/elmah/browse_thread/thread/33d2597ad0fd15cd
A MySQL provider should be straight-forward to implement. To be honest, I’m quite surprised that it has not been done already!
If you still need help, feel free to contact me via the form on my website:
http://leekelleher.com/contact/
Cheers,
- Lee
Lee Kelleher
June 8, 2009 at 5:17 am
Thanks for sharing, works perfect with umbraco (using the MS SQL edition)
Christian Palm
June 11, 2009 at 1:48 pm
[...] a comment » Following on from my last post (a couple of months ago) about Integrating ELMAH with Umbraco, I received a comment if it was possible for ELMAH to use MySQL as a back-end [...]
MySql data-source support for ELMAH « Lee Kelleher’s Weblog
June 29, 2009 at 11:28 am
Excellent thanks.
I made this tweak to get the iframe filling the panel.
<style>
.tabpageContent{height:100%;}
#elmahFrame{border:0;}
</style>
<iframe height=”98%” width=”100%” scrolling=”auto” src=”elmah.axd” style=”margin-top:5px;” id=”elmahFrame”></iframe>
Murray
September 2, 2009 at 10:54 pm
Thanks Murray, I’ve been meaning to get around to posting a fix for it in Umbraco v4.
(I combined your 2 comments into 1 btw)
I’ve been working on tighter ELMAH integration in my sparse [sic] time – building it as a custom appTree.
Lee Kelleher
September 2, 2009 at 11:02 pm
Hi Lee,
did you try securing elmah?
I have a problem with it, in that umbraco does not seem to login using standard .net authorization ‘roles’.
Here’s the bit of the web.config that’s not working: (this denies access to everyone)
<location path=”elmah.axd”>
<system.web>
<authorization>
<allow roles=”Administrators”/>
<deny users=”*” />
</authorization>
</system.web>
</location>
Or do I have the role name wrong?
Cheers.
Murray.
Murray
September 17, 2009 at 3:56 am
Hi Murray, I haven’t tried to set ELMAH up for remote access for a specific user group/role.
You could try the ELMAH support group forum? See if they have any ideas?
http://groups.google.com/group/elmah
Lee Kelleher
September 17, 2009 at 8:11 am
I recently was trying to get Elmah into one of my projects, but it was just not recording anything at all.
Turns out, that when you’re running on an asp.net 3.5 config (as opposed to 2.0), you need to add some more keys:
In system.webServer\modules, add:
And in system.webServer\handlers, add:
Sebastiaan Janssen
December 29, 2009 at 2:03 pm
And, since that didn’t work.. you can read all about it in this forum post
http://our.umbraco.org/forum/developers/extending-umbraco/6105-How-to-use-ELMAH-as-a-user-control-in-umbraco?p=0#comment22034
Sebastiaan Janssen
December 29, 2009 at 2:07 pm
Lee,
Just come across this again and realised I used this in a project I (and later you too!) worked on. Thanks for the info!
Rob
Rob Stevenson-Leggett
December 30, 2009 at 12:44 am
Hey Lee,
Thanks for the great post. However, I should say that it would be better to follow the instructions at http://our.umbraco.org/wiki/how-tos/use-elmah-with-umbraco because there is some code missing in your blog for some reason. There’s also a section that needs to be added when using the .NET 3.5 version. I can also confirm that the instructions work for Umbraco 4.5.1.
davidsiew
August 1, 2010 at 1:12 pm
Hi David, thanks for your comments.
Yeah, I wrote this blog post about 18-months ago, when I was still using Umbraco v3 and .NET 2.0.
I’ll add a message onto the Our Umbraco wiki page – which originally was based on this blog post!
Cheers,
- Lee
Lee Kelleher
August 1, 2010 at 1:39 pm