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
 <system.serviceModel>
  <extensions>
    <behaviorExtensions>
      <add name="workflowServiceTrace"
type="Microsoft.Activities.Extensions.Diagnostics.WorkflowServiceTraceElement, 
Microsoft.Activities.Extensions" />
    </behaviorExtensions>
  </extensions>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <!-- Other stuff here ....-->
        <workflowServiceTrace />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

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

 <configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="myListener" 
          type="System.Diagnostics.TextWriterTraceListener" 
          initializeData="TextWriterOutput.log" />
        <remove name="Default" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

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
etc.

Comments

  • Anonymous
    December 17, 2011
    You could also use my WorkflowServiceTrackingViewer on NuGet www.nuget.org/.../WorkflowServiceTrackingViewer

  • Anonymous
    December 19, 2011
    The comment has been removed

  • Anonymous
    December 19, 2011
    Sorry about that - the problem occured when I uploaded an update to the State Machine Hands On Lab that had the wrong Microsoft.Activities.UnitTesting in it.  I've corrected the lab so just download it again and give it a try.

  • Anonymous
    December 26, 2011
    I just wanted to throw a hearty Thank You to Ron for all your videos and other resources; they are much appreciated and key to product adoption!