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.