Advanced Error Reporting in Umbraco, dasBlog and other ASP.Net sites
Friday, February 27, 2009 3:51:13 PM (GMT Standard Time, UTC+00:00)
If you've been following my blog you'll know that I've been raving about error reporting within ASP.Net (you can see my ASP.Net Error Reporting category for a couple of them if you like) but until now it's been limited to those sites that you have access to the global.asax file.
One of the irritations I've found with Umbraco and dasBlog is that I don't get notified of errors as they're just logged to a text file/database somewhere. This is fine if you run 2 or 3 sites but we manage too many to check them all everyday. Instead we rely on email error notifications which until today have been a PITA to integrate into Umbraco.
Today I'd like to introduce to you Error Handling v2.0 which instead of relying on the global.asax file for the error hooks, uses a HttpModule which means you can install it into any existing/pre-built application such as Umbraco and dasBlog.
Adding it into the site is simple, you'll need to install the module into the web.config file and add the configuration section a sample (cut down) web.config is below:
<?xml version="1.0"?> <configuration> <configSections> <section name="tsdErrorsConfigSection" allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" type="System.Configuration.NameValueFileSectionHandler, System, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </configSections> <tsdErrorsConfigSection file="ErrorHandling.config"/> <system.net> <mailSettings> <smtp from="firstname.lastname@example.org"> <network host="127.0.0.1" port="25" /> </smtp> </mailSettings> </system.net> <system.web> <httpModules> <add name="ErrorModule" type="TheSiteDoctor.ErrorHandling.ErrorModule, TheSiteDoctor.ErrorHandling" /> </httpModules> </system.web> <!--...--> <!-- IIS 7 Settings <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules> <add name="ErrorModule" type="TheSiteDoctor.ErrorHandling.ErrorModule, TheSiteDoctor.ErrorHandling" /> </modules> </system.webServer> --> </configuration>
Then you'll need to check all the settings -I recommend storing these in another .config file for clarities sake. Make sure you've configured your SMTP settings and you should be good to go.
If you want to test your settings, I've included a test page for you that will check your settings and show you the defaults if you've not set them. I've got this running now on a couple of Umbraco and dasBlog installs without an issue.
There's also a useful logging system in it which I'll look to overview in a later post but if you want to see it, check out the included aspx file.
Download ErrorHandling_v2.0.zip (25Kb)
If you do use this code I'd be interested to hear how you get on, I think it requires a little more refinement un some areas but it's pretty robust.