This project is read-only.

How to use Health Monitoring in WCF

J.D. Meier, Jason Taylor, Prashant Bansode, Carlos Farre, Madhu Sundararajan, Steve Gregersen.

Use the following steps to configure your WCF service to use Health Monitoring:
  1. Create a custom health monitoring event.
  2. Configure your WCF service for health monitoring.
  3. Instrument your application to raise a custom event.
  4. Create a custom health monitoring event

Create a Custom user management web event, by creating a class library and then create a class that inherits from WebAuditEvent.
using System.Web.Management;

public class MyEvent : WebAuditEvent

    public MyEvent(string msg, object eventSource, int eventCode)
        : base(msg, eventSource, eventCode)

    public MyEvent(string msg, object eventSource, int eventCode, int eventDetailCode)
        : base(msg, eventSource, eventCode, eventDetailCode)
    public override void FormatCustomEventDetails(WebEventFormatter formatter)

        // Display some custom event message
        formatter.AppendLine("Some Critical Event Fired");
  1. Configure your WCF Service for Health Monitoring
Add a health monitoring element to your configuration file as follows:
			<add name="Some Custom Event" type="MyEventLibrary.MyEvent, MyEventLibrary"/>
			<add name="Custom event" eventName="Some Custom Event" provider="EventLogProvider" minInterval="00:00:01"/>
  1. Instrument your application to raise a custom event
Instrument the WCF Service by raising the custom event in a service contract.
string InvokeCriticalEvent();

public string InvokeCriticalEvent()
    MyEvent obj = new MyEvent("Invoking Some Custom Event", this, WebEventCodes.WebExtendedBase + 1);
    return "Critical event invoked";

When these steps are complete you can verify that the custom events are in the system event log after calling the service method from a test client.

Last edited May 8, 2008 at 12:38 AM by prashantbansode, version 1


No comments yet.