Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Tracking Using a Text File

This topic applies to Windows Workflow Foundation 4 (WF4).

This sample demonstrates how to extend tracking in Windows Workflow Foundation (WF) by creating a custom tracking participant. Tracking participants are .NET Framework classes that receive tracking records from the runtime as they are emitted. You can create a tracking participant to transport the tracking events to whichever destination is required for your scenario. For example, ETW (Event Tracing for Windows) Tracking Participant is provided as part of the .NET Framework. The tracking participant in this sample writes the records in XML format to a text file.

Sample details

To optimize the usefulness and robustness of your tracking participant, some additional steps must be completed to properly wire the tracking participant to the runtime. The following table describes the classes used in this sample to create a tracking participant that complies with best practices.

Class Description

TextFileTrackingExtensionElement

A BehaviorExtensionElement is used to define the configuration section used to configure the text file tracking participant. This allows users to specify the destination of the log file using standard .NET Framework configuration files.

TextFileTrackingBehavior

Behaviors in WCF allow users to inject extensions into the runtime. This behavior adds the tracking participant to the service when the service starts.

TextFileTrackingParticipant

The tracking participant that receives tracking participants at runtime and stores them to a log file as XML.

Behavior Extension Elements Configuration

One more step is required to make use of the behavior extension element previously described using .NET Framework configuration files. The following configuration must be placed in configuration files where the extension is to be used.

<system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="textFileTracking" type="Microsoft.Samples.TextFileTracking.TextFileTrackingExtensionElement, WFStockPriceApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>
…
  </system.serviceModel>

Ee667247.note(en-us,VS.100).gifNote:
See the Web.config file in the sample for a complete example usage of behavior extension elements configuration.

Custom Tracking Records

The GetStockPrices.cs file demonstrates how to create custom tracking records from within a CodeActivity. Look for this record when running the sample.

To use this sample

  1. Using Visual Studio 2010, open the WFStockPriceApplication.sln solution file.

  2. To build the solution, press CTRL+SHIFT+B.

  3. To run the solution, press CTRL+F5.

    The browser window opens and shows the directory listing for the application.

  4. In the browser, click StockPriceService.xamlx.

  5. The browser displays the StockPriceService page, which contains the local service wsdl address. Copy this address.

    An example of the local service wsdl address is http://localhost:53797/StockPriceService.xamlx?wsdl.

  6. Using Windows Explorer, go to your Visual Studio 2010 folder (the default installation folder is %SystemDrive%\Program Files\Microsoft Visual Studio 10.0). Then locate the Common7\IDE\ subfolder.

  7. Double-click the WcfTestClient.exe file to launch the WCF Test Client.

  8. In the WCF Test Client, select Add Service… from the File menu.

  9. Paste the URL you just copied into the text box.

  10. Click OK to close the dialog.

  11. Test the service using the WCF Test Client.

    1. In the WCF Test Client, double-click GetStockPrice() under the IStockPriceService node.

      The GetStockPrice() method appears in the right pane, with one parameter.

    2. Type in Contoso as the value for the parameter.

    3. Click Invoke.

  12. See the tracked events in the log file located in your application data directory at %APPDATA%\trackingRecords.log.

    Ee667247.note(en-us,VS.100).gifNote:
    The %APPDATA% is an environment variable that resolves to %SystemDrive%\Users\<username>\AppData\Roaming in Windows Vista, Windows Server 2008, or Windows Server 2008.

Ee667247.Important(en-us,VS.100).gif Note:
The samples may already be installed on your computer. Check for the following (default) directory before continuing.

<InstallDrive>:\WF_WCF_Samples

If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.

<InstallDrive>:\WF_WCF_Samples\WF\Basic\Tracking\TextFileTracking

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.