Skip to content

Instantly share code, notes, and snippets.

@vbilopav
Created September 1, 2015 13:37
Show Gist options
  • Save vbilopav/4e0575af9f81c1a92b31 to your computer and use it in GitHub Desktop.
Save vbilopav/4e0575af9f81c1a92b31 to your computer and use it in GitHub Desktop.
public class WcfErrorHandler : IErrorHandler
{
public bool HandleError(Exception error)
{
return false;
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
if (error == null)
{
return;
}
Log.Error(error, source: error.Source);
}
}
[AttributeUsage(AttributeTargets.Class)]
public class WcfErrorHandlerAttribute : Attribute, IEndpointBehavior, IServiceBehavior
{
public void Validate(ServiceEndpoint endpoint)
{
}
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new WcfErrorHandler());
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
}
public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
}
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers)
{
channelDispatcher.ErrorHandlers.Add(new WcfErrorHandler());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment