I am new to Work Flows. I have created a small workflow. and put a few custom activities in it.
Now i would like to log the status of this activities as and when they complete and what where its input and output parameters.
Similar to one which we see in TFS Build.
You can define a TrackingParticipant
as an extension to add for a WorkflowApplication
.
Custom Tracking Participant
using System.Activities.Tracking;
public class MyTrackingParticipant : TrackingParticipant
{
protected override void Track(TrackingRecord record, TimeSpan timeout)
{
if (record is WorkflowInstanceRecord)
{
var wfInstanceRecord = record as WorkflowInstanceRecord;
Console.WriteLine($"My workflow's current state: {wfInstanceRecord.State}");
}
if (record is ActivityStateRecord)
{
var activityStateRecord = record as ActivityStateRecord;
Console.WriteLine($"Activity: {activityStateRecord.Activity.Name} State: {activityStateRecord.State} Timestamp: {activityStateRecord.EventTime}");
}
}
}
Register the Custom Tracking Participant
var wfApp = new WorkflowApplication(myActivity);
wfApp.Extensions.Add(new MyTrackingParticipant());
wfApp.Run();