In our WF4 workflow service, we try to be as robust as possible. One of the things we do is to log errors inside HandleError and ProvideFault (IErrorhandler). The documentation states clearly that HandleError would be the right place to do the logging, but I see some strange things happen:
I see some errors that only trigger ProvideFault, but never HandleError, one example was:
System.NullReferenceException: Object reference not set to an instance of an object. at System.ServiceModel.Activities.Dispatcher.DurableInstanceManager.GetInstanceAsyncResult.GetInstance() at System.ServiceModel.Activities.Dispatcher.DurableInstanceManager.GetInstanceAsyncResult..ctor
There are also some errors that only trigger HandleError, but never ProvideFault, one example was:
System.ServiceModel.CommunicationException: There was an error reading from the pipe: The pipe has been ended. (109, 0x6d). at System.ServiceModel.Channels.PipeConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) at System.ServiceModel.Channels.SessionConnectionReader.Receive(TimeSpan timeout)
Finally there are errors that trigger both, first ProvideFault and then HandleError (on a background thread)
If possible, I want to log the corresponding incoming message, too. I do this with OperationContext.Current.RequestContext.RequestMessage.ToString() This usually only works in ProvideFault, in HandleError we don't have the RequestContext any more
So my conclusion was, to log ALL errors, I must log in both methods. But that leads to a lot of duplicated log entries, due to 3..
My current workaround was to "remember" the last logged exception from ProvideFault, and igno