Tracing Windows Workflow
Here’s a small little pearl I found while playing with Windows Workflow; WWF provides tracing through System.Diagnostics. This is not tracking (which is a full blown service in WWF) but simple tracing, showing which workflows and activity has been executed.
The System.Diagnostics in .NET 2.0 should be familiar with anyone who’s used Enterprise Library in .NET 1.1.
To enable tracing on your Windows Workflow application add an app.config file to your application and in the <configuration> section add a <system.diagnostic> section.
System.Diagnostic has 2 sections in it: <switches> and <trace>. <switches> contains the tracing options and information levels and <trace> tells the system where to write the trace file to (For more information on System.Diagnostic read it up on MSDN)
There are 5 classes provided by Windows Workflow to use: WorkflowTraceToDefault, Host, Runtime, Tracking and Activity. The last 4 classes are Trace Switches, are optional and have 5 states: Off, Error, Warning, Info, Verbose (although All seems to be able to replace Verbose). The first class is a Boolean Switch and is a required field. Tracing is off by default for Windows Workflow so you’ll have to enable WorkflowTraceToDefault to get results.
Here’s an example of enabling Tracing:
<system.diagnostics>
<switches>
<add name="WorkflowTraceToDefault" value="1" />
<add name="Host" value="Error" />
<add name="Runtime" value="Warning" />
<add name="Tracking" value="Info" />
<add name="Activity" value="All" />
</switches>
<trace autoflush="true" indentsize="4">
</trace>
</system.diagnostics>