Automated e-mailing of errors from a website.

by Dominic Zukiewicz 14. May 2007 16:04
There is so much useful stuff to learn about through the MCTS path.

Don't you just hate having to write a common functionality class that e-mails you with errors?

Well, you've wasted your time, as ASP .NET 2.0 does this for you without you writing a single line of code.

Here is what you do:

1) Add a health monitoring section
<configuration>
    <system.web>
       <healthMonitoring enabled="true" heartbeatInterval ="0">
       </healthMonitoring>
   </system.web>
</configuration>
2) Add a providers section inside the health monitoring to alert any listening providers (WMI, E-mail, SQL, EventLog etc) to your errors/events.

<providers>
<add
to="destination@myemail.com"
from="source@myemail.com"
  subjectprefix="Error has occurred!"
buffer="false"
type="System.Web.Management.SimpleMailWebEventProvider"
name="Email Provider"
/>
</providers>
3) We also need to add some rules, i.e. a filtering system to get the error message we need. Because to can get failure in audit events, informational, warning etc, I'm going to make one which watches for the Errors only.
<rules>
<add
name="Testing Mail Event Providers"
eventName="All Errors"
provider="Email Provider" <!-- Defined above -->
profile="Default"
minInstances="1"
maxLimit="Infinite"
minInterval="00:01:00" <!-- Sends the e-mails in 1 minute batches -->
/>
</rules>
4) Now, when errors are thrown up to the top level (which can be viewed in the Application_Error() method), an e-mail will be sent. If you didn't configure the customErrors tag in the web,config, you'll get a lovely yellow error screen and an e-mail as a reminder of the error.

Very VERY handy! And no code required - well - except to fix the problem!

Tags:

Debugging & Exception Handling

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar