Health Monitoring in ASP.NET 2.0
This topic is covered by others before but this post by Rick pinged me to write about it to give an introduction for one of my incoming posts.
Rick as an administrator for a shared host, ASPnix, has disabled debugging on their servers but their clients got in trouble to debug their applications and are looking for a way. Rick contacted Scott and he suggested to use ASP.NET 2.0 Health Monitoring feature then create a simple reporting system to let users be aware of their application errors.
I want to write a very simple report system for him so will produce an introduction to Health Monitoring in ASP.NET 2.0 in this post.
Who doesn't know?! It's strongly recommended to disable debugging for your ASP.NET applications before deploying them to server but often developers forget it and this eats their server's resources. When it comes to a shared host, problem gets bigger and some hosters disable debugging on their servers via machine.config. But there are some errors that arise when an applications deploys on server and developers need to be aware of them.
On the other hand any professional site needs a mechanism to log its events/errors and lets its admin(s) to solve them. This mechanism is provided in Community Server for ASP.NET 1.1 and 2.0 both and I talked about it here. But ASP.NET 2.0 came with a new feature called Health Monitoring to assist developers and admins to easily set up it and log their application events.
ASP.NET 2.0 enables you to log your site events into SQL Server database, get them via email, log them in server's Event Logs, map them to Windows Management Instrumentation or write your own custom provider for this purpose.
Scott Allen had a post about this feature that you can read.
As same as Membership or Role Manager you can configure your Health Monitoring to use a provider and choose which kind of events should be logged via your Health Monitoring configurations. For instance I create a simple website, use aspnet_regsql via command prompt to prepare my SQL Server database and put following code in my Web.config:
<healthMonitoring enabled="true">
<providers>
<add
name="SqlEventProvider"
connectionStringName="Health"
maxEventDetailsLength="1000000"
buffer="false"
bufferMode="Notification"
type="System.Web.Management.SqlWebEventProvider,
System.Web,Version=2.0.0.0,Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
<rules>
<add name="AllEvents"
eventName="All Events"
provider="SqlEventProvider"/>
</rules>
</healthMonitoring>
It uses Health connectionstring to connect to my database and log all events in my application. Now I put a simple code like what follows in one of my web pages to throw a new exception:
protected void Page_Load(object sender, EventArgs e)
{
throw new ApplicationException
("This is an error thrown to be logged in database.");
}
After hitting this page I'll get an error. Now I open my database and see the list of application events. This error is logged there:
I could configure my Health Monitoring to only save application errors as well. For more information about Health Monitoring in ASP.NET 2.0 refer to MSDN.
I'll write a simple reporting ASP.NET 2.0 website to list all errors for users. More will come soon.
[advertisement] Axosoft OnTime 2008 is four developer tools in one: bug tracking, project wiki, feature management, and help desk. It manages your development process so developers can focus on coding. Installed or Hosted – Free Single-user license -- Free 30-day team trial.
10 Comments : 09.14.06

#1
Jaxon Rice
09.14.2006 @ 5:51 AM