Set It and Forget It

What do Ronco, car insurance, and Error Logging Modules andHandlers (ELMAH) have in common? They all tout a “set it and forget it”approach. Jonathan Goodyear explains.

Jonathan Goodyear

October 30, 2009

4 Min Read
ITPro Today logo in a gray background | ITPro Today

Back Draft

 

Set It and Forget It

 

By Jonathan Goodyear

 

If you ve watched any amount of television here in the United States lately, you ve likely seen theplethora of car insurance commercials. While some of them are amusing to watch,it always surprises me how they try to make the topic of car insurance seemlike a central theme to the average person s life. While just about everybodywho owns a car also has car insurance (it s the law in most places), it s justnot something that most people spend much time thinking about. You do a littlebit of research, pick a provider that meets your needs, and you re done. I havepersonally had the same car insurance provider for the last decade. I recallthe famous slogan coined by the infomercial king Ron Popeil of Ronco, Set Itand Forget It (http://en.wikipedia.org/wiki/Ronco).That summarizes my feelings about car insurance quite nicely.

 

All of that said, you put yourcar insurance in place for a reason. When the unfortunate (some would sayinevitable) accident occurs, you want your car insurance provider to springinto action and do its job to take care of things. I like programming toolsthat work the same way. I can take the time to set them up once, then they llget out of my way until I need them at which point, they ll perform their jobexactly as I intended. In fact, keeping with the theme of accidents, there is afree tool at your disposal that won t get in your way and can handleprogrammatic accidents (exceptions) quite gracefully.

 

The tool to which I am referring is ELMAH (Error LoggingModules and Handlers; http://code.google.com/p/elmah/).At its core, ELMAH is a pluggable exception management and logging engine forASP.NET. It is implemented as a set of HttpModules and HttpHandlers that youcan drop into any existing ASP.NET application to manage and log all unhandledexceptions. I particularly like the fact that it doesn t require you to changeany of your code to make it work. Drop an assembly into your /bin directory andadd a couple of lines of code to your web.config file (to let your ASP.NETapplication know that ELMAH is in the house) and you re good to go. You caneven add the ELMAH assemblies to the Global Assembly Cache (GAC) and instantlyget exception handling and logging for all the ASP.NET applications on anentire Web server.

 

Note that there are a couple of extra entries that you llneed to add to your machine.config file to enable this option. If you have anASP.NET application and don t yet have a cohesive strategy to account for theunexpected, I highly recommend ELMAH. You ll especially appreciate the factthat you can access a log of the exceptions generated by your application via aWeb page or RSS feed. If you want a more direct approach, you can even haveeach exception e-mailed to you.

 

Some of you may be wondering why I haven t mentioned theException Handling Application Block, which is one of the pieces of theEnterprise Library suite created by Microsoft s Patterns & Practices team (http://msdn2.microsoft.com/en-us/library/aa480461.aspx).In fact, I do like the Exception Handling Application Block. Besides basicexception handling and logging, it also includes the ability to set policiesfor different types of exceptions or exceptions that occur in different parts(tiers) of your application, as well as enabling you to wrap exceptions. Thisprovides a great security barrier when interfacing with external applicationsthrough interfaces such as Web services.

 

However, the Exception Handling Application Block can be abit of overkill for most ASP.NET applications. While there are multiple loggingoptions, it prefers to send events to the Windows Event Log, which requiresspecial permissions that ASP.NET does not have by default. It also requiresmore code to implement. Overall, it s a more powerful solution; my company usesit for several of our clients for whom we are building applications thatutilize Windows Presentation Foundation (WPF) and Windows CommunicationFoundation (WCF). In those environments, the Exception Handling ApplicationBlock s additional flexibility is worth the extra work to implement it. Formost ASP.NET applications, though, I prefer to Set It and Forget It . Forthat, ELMAH truly shines.

 

Jonathan Goodyearis president of ASPSOFT (http://www.aspsoft.com), an Internet consulting firm based in Orlando, FL. Jonathanis Microsoft Regional Director for Florida,an ASP.NET MVP, a Microsoft Certified Solution Developer (MCSD), and co-authorof ASP.NET 2.0 MVP Hacks (Wrox).Jonathan also is a contributing editor for asp.netPRO.E-mail him at mailto:[email protected] orthrough his angryCoder eZine at http://www.angryCoder.com.

 

 

 

 

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like