Healthmonitoring in ASP.NET 2.0 (EIF++)
The next version of ASP.NET (2.0) finally comes with a built-in logging mechanism:
Healthmonitoring.
I've just been experimenting with it (using my Visual Web Developer 2005 Express Edition Beta1), and it really rocks! It's got the power of EIF (Enterprise Instrumentation Framework) combined with the simplicity of Log4NET. Moreover, ASP.NET 2.0 Healthmonitoring offers a lot of common event-sinks, like EvenLog, Email, TemplatedEmail, File, Wmi and SQLServer.
Besides logging of events, there's a 'heartbeat' feature, giving you the power to do monitoring of your app.
There's still very little (like "none") documentation about Healthmonitoring, so maybe you want to know how I managed to log my own events to the default ASP.NET SQLServer sink:
Step 1: run aspnet_regsql.exe; this will create the 'aspnetdb' database on your SQLServer
Step 2: create your own event derived from a BaseEvent (I called mine 'MyWebEvent'). Note: only custom events with an eventCode > WebEventCodes.WebExtendedBase will be logged by ASP.NET 2.0!
public class MyWebEvent : WebBaseEvent
{
public MyWebEvent(string msg, object eventSource, int eventCode) :
base(msg, eventSource,WebEventCodes.WebExtendedBase + eventCode) {}
public MyWebEvent(string msg, object eventSource, int eventCode, int eventDetailCode) :
base(msg, eventSource, WebEventCodes.WebExtendedBase + eventCode, eventDetailCode) {}
public override void Raise()
{
base.Raise();
}
}
Step 3. Enable healthMonitoring in your web.config (see below). Besides my own 'MyWebEvent' events, I also log all Exceptions that were raised in my webapp (as you can see in the 'rules' section). If you want to know what the default built-in Providers, EventMappings and Rules are, please have a look at the 'machine.config.comments' file (inside the Config folder of your .NET installation). Note: when you've put your event-class code in the /Code folder, please first do a 'build all' before enabling healthMonitoring in your web.config (else ASP.NET 2.0 won't be able to create the type of your event).
<
system.web><healthMonitoring enabled="true">
<providers>
<clear />
<add name="SqlWebEventProvider" type="System.Web.Management.SqlWebEventProvider" connectionStringName="LocalSqlServer" />
</providers>
<eventMappings>
<add name="MyEvent" type="MyWebEvent" />
</eventMappings>
<rules>
<clear />
<add provider="SqlWebEventProvider" name="All Errors Default" eventName="All Errors" />
<add provider="SqlWebEventProvider" name="My Custom events" eventName="MyEvent" />
</rules>
</healthMonitoring>
Step 4. Now raise your own event somewhere in your web-application !!
MyWebEvent myWebEvent = new MyWebEvent("Dion was here", this, 1);
myWebEvent.Raise();
See also: http://msmvps.com/gbvb/archive/2004/09/15/13578.aspx