Vineet Batta here,

A little known but excellent features of ASP.NET is it’s ability to give support teams the ability to monitor the health of ASP.NET applications. In this article I will dwell on out of box features. No custom classes or code to be written. All the configuration setting for enabling Health monitoring (HM) are done in web.config. There are three core sections which you should be aware of while implementing HM;

  • Providers – Event log provider
  • EventMapping - Event mapping provides a friendly name to the events
  • Rules - Rule tying the "All Errors" and "Failure Audits" event mapping to the EventLog Provider

Event Mapping supported are;

<add name="All Events"  />
<add name="Heartbeats"    />            
<add name="Application Lifetime Events"  />               
<add name="Request Processing Events"  />               
<add name="All Errors"   />             
<add name="Infrastructure Errors"   />              
<add name="Request Processing Errors"        />          
<add name="All Audits"          />       
<add name="Failure Audits" />               
<add name="Success Audits"  />

Complete list of Event mappings, Providers and Rules is provided in web.config (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG).

An example of Health Monitoring configuration as created for logging messages into Event log. We used the similar configuration as above in one of the applications and were able to completely avoid any code on global.ascx or matter of fact in code behind.

<healthMonitoring enabled="true">
<!--  Event Log Provider being added. -->
	<add name="EventLogProvider" type="System.Web.Management.EventLogWebEventProvider,System.Web,Version=,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"/>
	<!--  Event mapping provides a friendly name to the events based on the WebBaseErrorEvent class.  -->
	<add name="All Errors" type="System.Web.Management.WebBaseErrorEvent,System.Web,Version=,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/>
        <add name="Failure Audits" type="System.Web.Management.WebFailureAuditEvent,System.Web,Version=,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647"/>
	<!-- Rule tying the "All Errors" and "Failiure Audits" event mapping to the EventLog Provider.  -->
	<add name="All Errors Default" eventName="All Errors" provider="EventLogProvider" profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:00:00" custom=""/>
	<add name="Failure Audits Default" eventName="Failure Audits" provider="EventLogProvider" profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:00:00" custom=""/>

You can also support sending emails by choosing a different provider namely – EmailErrorProvider.

<add name="EmailErrorProvider"
             subjectPrefix="Application failure."
             bodyHeader="This email is generated from my application." />

You can also configure  logging into SQL server by configuring the correct provider as - SqlWebEventProvider

  <add connectionStringName="LocalSqlServer" 
maxEventDetailsLength="1073741823" buffer="false" 
name="SqlWebEventProvider" type="System.Web.Management.SqlWebEventProvider,System.Web,Version=,Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />

So as you saw how easy and useful this feature is for monitoring the health of applications with so little effort. Latter I may explain how to extend this framework feature with custom classes.

Tip of the day

Recently we upgraded our production environment application bits and were required to encrypt Sql connection string(every one should do it) which has sensitive information like username/password. Soon realized it was working for some of us who were administrators on  the box and rest were getting the following error error message…

Exception information: 
    Exception type: ConfigurationErrorsException 
    Exception message: Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: The RSA key container could not be opened. (E:\webroot\web.config line 56)  


After few hrs of looking around we got to the root of the problem and the conclusions was that we need to give access to this RSA Container to all Authenticated users. How?

aspnet_regiis -pe "connectionStrings" /<your app name> "/"
aspnet_regiis -pa "NetFrameworkConfigurationKey" "everyone"


Hope this helps and saves you time.