I'm trying to set up Raygun.io on a WCF service, and despite the simple instructions on the site, am having little luck getting things running.
I've signed up for my account, installed the Mindscape.Raygun4Net
package via Nuget, then tried the following methods:
Web.config approach:
I added the config section, the Raygun section with my affiliate key, then added the module under system.webserver
. Nothing was logged.
Global.asax approach:
I tried adding a RaygunClient
object to global.asax and then sending the exception on Application_Error
. Nothing was logged and the breakpoint inside Application_Error
was never hit.
IErrorHandler Approach: This one actually got the errors logging to Raygun, but had its own issues:
Error Handler:
public class RaygunLogger : IErrorHandler
{
private RaygunClient _client = new RaygunClient("5xqBOzTBrzIsS++3vsbFZw==");
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
}
public bool HandleError(Exception error)
{
_client.Send(error);
return false;
}
}
Behavior:
public class RaygunServiceBahavior : IServiceBehavior
{
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints,
BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
IErrorHandler errorHandler = new RaygunLogger();
foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers)
{
channelDispatcher.ErrorHandlers.Add(errorHandler);
}
}
public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
}
}
Behavior Extension:
public class RaygunBehaviorExtensionElement : BehaviorExtensionElement
{
public override Type BehaviorType
{
get { return typeof(RaygunServiceBahavior); }
}
protected override object CreateBehavior()
{
return new RaygunServiceBahavior();
}
}
The exception would be thrown, then the Handle_Error
method would be called, sending the error to Raygun, but it always sends two exceptions instead of one. The first exception is an ObjectDisposedException: The message object has been disposed
.
Has anyone had luck setting up Raygun on WCF? If so, do you have the same behavior or can you see anything I'm doing differently?