views:

105

answers:

1

hi guys,

I need a final answer to the following question! :-)

I was wondering if you can enable Health Monitoring for WCF Web services. I'm hosting a number of services in IIS and configured it to send the team email notification when any exceptions are thrown. I feel that Health Monitoring does not work with WCF Services and that I have to configure WCF Tracing http://msdn.microsoft.com/en-us/library/ms733025.aspx

Thank you

+2  A: 

I tried it before too, but all solutions looked too complex.

I ended up just do it manually.

First setup a custom WebEvent. Eg:

public class SyncError : WebBaseErrorEvent
{
  public SyncError(string message, Exception e)
    : base(message, "Sync", WebEventCodes.WebExtendedBase + 1, 0, e)
  {    
  }

  public override void FormatCustomEventDetails(WebEventFormatter formatter)
  {
    base.FormatCustomEventDetails(formatter);
    formatter.AppendLine(ErrorException.ToString());
  }
}

Next use it like:

// WCF method
public int Sync()
{
  try
  {
    // do normal stuff
  }
  catch (Exception ex)
  {
    var e = new SyncError("Error in Sync", ex);
    e.Raise();
    throw;
  }
}

Finally, modify the web.config:

<eventMappings>
  <add name="Sync Errors" type="SyncLibrary.SyncError, SyncLibrary"/>
</eventMappings>

<rules>
  <add name="Sync Errors SQL" eventName="Sync Errors" 
       provider="SqlWebEventProvider"
       profile="Default" 
       minInstances="1" 
       maxLimit="Infinite" 
       minInterval="00:00:00" />
</rules>

Note: this assumes you have health-monitoring turned on.

leppie
Thanks leppie! let me implemente it today and I will let you know! Cheers,Juan
elsharpo
mister elsharpo, will you let know it ?? thanks
alhambraeidos