Ron Jacobs

Windows Workflow Foundation

Troubleshooting Workflow Services with diagnostic logging

Troubleshooting Workflow Services with diagnostic logging

Rate This
  • Comments 4

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.
  • You could also use my WorkflowServiceTrackingViewer on NuGet www.nuget.org/.../WorkflowServiceTrackingViewer

  • Ron,

    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:\develop\reference\workflow\Windows Workflow Foundation (WF4) - Introduction to State Machine Hands On Lab\C#\Assets\AtmStateMachine.Tests\AtmMachineTests.cs 82 17 AtmStateMachine.Tests"

    Do you have suggestions?

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

  • 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!

Page 1 of 1 (4 items)