In the previous articleArticle Http://www.cnblogs.com/carysun/archive/2011/01/23/WF4-ETW.htmlWe talked aboutWf4InETW Tracking reference, this is Wf4 Let's take a look at the structure of this class:
etwtrackingparticipant ipant inherited from trackingparticipant ipant class, if we want to customize our own tracking referers, we also inherit this class. We only need to rewrite the corresponding method, we will customize a trail reference by workflow information is written to the file:
Public Class Txtfiletrackingparticipant ipant:Trackingparticipant ipant
{
StringFilename ="";
Protected Override VoidTrack (TrackingrecordRecord,TimespanTimeout)
{
Filename =@ "C :\"+ Record. instanceid +". Txt";
Using(StreamwriterSw =File. Appendtext (filename ))
{
Sw. writeline ("---------- Begin tracking ----------");
Sw. writeline (record. tostring ());
Sw. writeline ("---------- End tracking ----------");
}
}
}
We simply design a workflow, and thenTxtfiletrackingparticipant ipantAdded to the workflow extension point,CodeAs follows:
Class Program
{
Static VoidMain (String[] ARGs)
{
// ETW tracking setup
TrackingprofileTrackingprofile =New Trackingprofile();
Trackingprofile. Queries. Add (New Workflowinstancequery
{
States = {"*"}
});
Trackingprofile. Queries. Add (New Activitystatequery
{
States = {"*"}
});
Trackingprofile. Queries. Add (New Customtrackingquery
{
Activityname ="*",
Name ="*"
});
Txtfiletrackingparticipant ipantTxtfiletrackingparticipant ipant =New Txtfiletrackingparticipant ipant();
Txtfiletrackingparticipant. trackingprofile = trackingprofile;
AutoreseteventAutoresetevent =New Autoresetevent(False);
WorkflowapplicationWorkflowapplication =New Workflowapplication(New Workflow1());
Workflowapplication. Completed = (ARG) =>{ autoresetevent. Set ();};
Workflowapplication. Extensions. Add (txtfiletrackingparticipant ipant );
Workflowapplication. Run ();
Autoresetevent. waitone ();
}
}
Then we run the workflow. After the workflow is complete, we will see that the tracking information has been recorded in the text file as follows:
You can record the tracing information of a workflow to the media you need in a similar way.