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

Comments (4)

  1. PeteGoo says:

    You could also use my WorkflowServiceTrackingViewer on NuGet…/WorkflowServiceTrackingViewer

  2. Todd says:


    I had hoped to commented on article "Visual Studio 11 Preview and .NET 4 Platform Update 1 Side by Side Bug" but could not so I have to do it here. Sorry about that.

    After I updated targets file as suggested in your article, I ran into another problem. The compiler complained that it could not find AssertState in line 82 and other in AtmMachineTests. I looked at the dll and found one similar object with the same method name as AssertHelper.OccursInOrder, but it then told me "Error 1 The type arguments for method 'Microsoft.Activities.UnitTesting.AssertHelper.OccursInOrder<T>(System.Collections.Generic.IEnumerable<T>, params T[])' cannot be inferred from the usage. Try specifying the type arguments explicitly. D:developreferenceworkflowWindows Workflow Foundation (WF4) – Introduction to State Machine Hands On LabC#AssetsAtmStateMachine.TestsAtmMachineTests.cs 82 17 AtmStateMachine.Tests"

    Do you have suggestions?

  3. Ron Jacobs says:

    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.

  4. Bruce Barstow says:

    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!

Skip to main content