After Thought

Archive for January 2011

Setting up Elmah in your application to log into FogBugz (Bug tracking system)

with 2 comments

ELMAH (Error Logging Modules and Handlers)  is a pluggable error logging system created by Atif Aziz that can be hooked onto an ASP.Net application. It is very straight forward to set up and gives options to log errors to several back-end storages including databases, in-memory, XML files and send out email notification. Scott Hanselman blogged about setting up ELMAH a while back. This is just an extension to that post to log the error to bug tracking system like FogBugz if you are using one.

Here is how to set up ELMAH on your ASP.Net MVC that logs an entry in FogBugz when there is an error. Fogbugz allows to log an error just by sending an email to the FogBugz connected mailbox. So we will set up ELMAH to send an email when there is an error.

Download ELMAH Core Binary and add it your library. Add a reference to Elmah.dll in your web project.

Add following entries to your web.config

<httpModules>
 ...
 <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
</httpModules>

<modules runAllManagedModulesForAllRequests="true">
 ...
 <add name="Elmah.ErrorMail" type="Elmah.ErrorMailModule" preCondition="managedHandler" />
 <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
 <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
</modules>
<handlers>
 <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" preCondition="integratedMode" type="Elmah.ErrorLogPageFactory, Elmah"/>
</handlers>

<configSections>
 <sectionGroup name="elmah">
 <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
 </sectionGroup>
</configSections>
<elmah>
 <errorMail
 from="from@domain.com"
 to="to@domain.com"
 subject="<Application Name> Error"
 async="false"
 useSsl="true|false"
 smtpPort="60"
 userName="username"
 password="password"
 smtpServer="smtp.domain.com" />
</elmah>

That is it. ELMAH is set up and your application is ready to log any errors to FogBugz.

Before you proceed any further check if ELMAH is properly set up by going to http://localhost/elmah.axd. You should get the following screen.

You will still encounter yellow screen when there is an error. You can always redirect users to a nice looking page if there is an error by configuring your customErrors section as follows.

<customErrors mode="On" defaultRedirect="~/Error/SomeError">
 <error statusCode="404" redirect="~/Error/NotFound"/>
</customErrors>
Advertisements

Written by shashankshetty

January 13, 2011 at 11:23 am

Posted in ASP.net, ASP.net MVC, C#, Uncategorized

Tagged with ,