Health monitoring in ASP.NET 2.0

by Mads Kristensen 25. April 2006 05:28

The new ASP.NET 2.0 provider model has once again amazed me. It lets you write to the EventLog, Sql Server and WMI as standard and lets you write your own provider that monitors the different events that occurs in a web application or ones you raise yourself. Read more on MSDN about using health monitoring in ASP.NET 2.0.

It also lets you send an email when an error occurs with writing anything but some lines in the web.config. This is amazing. I don’t know how many times I’ve written some code that would send me a mail when a critical or unexpected error happens. For smaller web applications, this is absolutely amazing, because you probably don’t want a big event logging framework when building a simple presentational website.

It is built so clever, that you don’t get an email every time an error occurs. You can set the interval or get with the one minute default. If five errors occur within that one minute, only one mail is sent with the information of all the errors so you mailbox won’t get flooded.

I couldn't find an example of how to use health monitoring to send an e-mail, but a lot of articles on the web led me in the right direction. After doing some research and trial-and-error I finally made it work.

Here is a very simple web.config file that sends an e-mail whenever an unhandled error occurs. Pay attention to the <healthMonitoring> and <system.net> section. These are the important ones that makes it work.

<?xml version="1.0"?>
<configuration>
   <appSettings/>
   <connectionStrings/>

   <system.web>
      <compilation debug="false" />
      <trace enabled="true" localOnly="false" />

      <healthMonitoring enabled="true">
         <providers>
            <add name="EmailProvider" 
               type="System.Web.Management.SimpleMailWebEventProvider"
               from="you@domain.com"
               to="you@domain.com"
               subjectPrefix="Error: "
               buffer="true"
               bufferMode="Notification" />
         </providers>
         <rules>
            <add provider="EmailProvider" name="All App Events" eventName="All Errors" />
         </rules>
      </healthMonitoring>

   </system.web>
   <system.net>
      <mailSettings>
         <smtp from="you@domain.com">
            <network host="smtp.domain.com" />
         </smtp>
      </mailSettings>
   </system.net>
</configuration>

How easy can it get? Truly amazing.

* Only $4.95/month ASP.NET & Windows 2008 + IIS 7 Hosting! FREE SQL Included

Tags:

ASP.NET

Comments

7/26/2006 9:30:43 AM #

 lb

thanks Mads...
i just wish i'd found this sooner!
very nice write up.
lb

lb |

8/9/2007 2:24:05 PM #

jonah

Your links do not work in your RSS feed. They are relative...

jonah United States |

8/9/2007 5:30:48 PM #

Dan Atkinson

This baby saved my bacon this morning. How co-incidental that you mentioned it in your post!

Dan Atkinson United Kingdom |

8/9/2007 10:46:12 PM #

Josh Stodola

Amazing indeed, I wish I would have known about this along time ago.  Thanks for sharing, Mads!

Josh Stodola United States |

8/10/2007 3:55:09 PM #

trackback

Trackback from MK2

使用Asp.net 2.0内建的健康状态监听器(health monitoring)

MK2 |

10/4/2007 3:22:31 PM #

TweeZz

For people who want to implement it, here are a few more references I used:
aspnetresources.com/.../..._health_monitoring.aspx
msdn2.microsoft.com/en-us/library/ms998306.aspx
all default event mappings: msdn2.microsoft.com/en-us/library/yc5yk01w.aspx

TweeZz |

12/19/2007 6:47:20 PM #

e

wow! this is just too easy!

soon we all will be out of jobs!

e United States |

2/29/2008 10:43:17 PM #

pingback

Pingback from gsmblog.com

Health monitoring in ASP.NET 2.0

gsmblog.com |

4/11/2008 3:33:23 AM #

trackback

Trackback from !Cool

ASP.NET health monitoring

!Cool |

4/13/2008 6:48:52 AM #

trackback

Trackback from !Cool

ASP.NET health monitoring

!Cool |

8/27/2008 3:04:12 AM #

trackback

Tools

Tools

The Luebbes: A Family Blog |

11/22/2008 10:40:52 AM #

Dale Sides

You mentioned setting an interval in your article but I don't see it in the example, could you post an example on how to implement it? Thanks again, I can remove a lot of code from some of my sites.

Dale Sides United States |

2/9/2010 7:06:35 AM #

pingback

Pingback from 70620.com

Microsoft 70-568 exam study guide | 70-620 Exam - Microsoft Questions on 70-620 Exam and Answers

70620.com |

4/11/2010 2:38:18 AM #

pingback

Pingback from healthandhealth.info

asp net health monitoring « Uncategorized « Health And Health

healthandhealth.info |

Comments are closed

About the slave

Mads Kristensen Mads Kristensen
Web developer at ZYB and founder of BlogEngine.NET. More...

LinkedIn ZYB Facebook Last.fm Twitter View Mads Kristensen's profile on Technorati

The Lounge

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008