Troubleshooting Workflow Services with diagnostic logging

Sometimes you have a workflow service that is misbehaving in a production environment.  How do you figure out what is going on when you can’t attach a debugger?

The solution is to use Workflow Tracking.  There are two alternatives you can try out

  1. Tracking using the System.Activities.Tracking.EtwTrackingParticipant see this Zoiner’s blog for a great quick start on this technique
  2. Tracking using Microsoft.Activities.Extensions and a text log file using a TextWriterTraceListener (keep reading for more)

Enabling Tracking to a Text File

Sometimes all you want is a just a text file with a log of what is happening. 

Step 1: Add Microsoft.Activities.Extensions to your web project

See How do I install Microsoft.Activities.Extensions?

Step 2: Enable the WorkflowServiceTraceBehavior

  • Open Web.config
  • Add the extension
  • Add the behavior
      <add name="workflowServiceTrace"
Microsoft.Activities.Extensions" />
        <!-- Other stuff here ....-->
        <workflowServiceTrace />

Step 3: Enable a trace listener

Note: Using TraceListeners in IIS can be a pain.  Typically you have to use some kind of logging framework.  For this simple example I’m using TextWriterTraceListener which will work find in a development environment but will probably fail in IIS unless the worker process has write permissions in the output folder..

Modify your web configuration to add the following for more info see TextWriterTraceListenerClass

    <trace autoflush="false" indentsize="4">
        <add name="myListener" 
          initializeData="TextWriterOutput.log" />
        <remove name="Default" />

Step 4: Run the Workflow

After running the workflow look at the log files to find tracking data waiting for you.

 0: WorkflowInstance "Sequential Service" is Started
1: Activity [null] "null" scheduled child activity [1] "Sequential Service"
2: Activity [1] "Sequential Service" is Executing
{     Variables         handle: System.ServiceModel.Activities.CorrelationHandle         data: 0
3: Activity [1] "Sequential Service" scheduled child activity [9] "ReceiveRequest"
4: Activity [9] "ReceiveRequest" is Executing