惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
B
Blog RSS Feed
WordPress大学
WordPress大学
A
About on SuperTechFans
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
I
InfoQ
MyScale Blog
MyScale Blog
量子位
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 叶小钗
J
Java Code Geeks
L
LangChain Blog
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志

博客园 - 生鱼片

Gitlab安装过程 SharePoint 2013即SharePoint 15的一些新特性 关于虚机克隆模板导致无法添加域用户的问题 http header Content-type SharePoint 2010 文档库中直接打开文档 使用SymbolResolver在Activity内访问宿主环境信息 增加一个Export to Spreadsheet的链接 WF4:ETW跟踪参与者 WF4集合Collection相关活动用法 SharePoint 2010 BI(2):使用Visio Service SharePoint 2010 BI (1):Chart WebPart 微软WebMatrix介绍 使用Sharepoint 2007中的webservice操作列表 - 生鱼片 - 博客园 SharePoint中CAML使用的一些总结 使用SharePoint Designer 2010 创建 外部内容类型 WF4:同步执行工作流 - 生鱼片 - 博客园 SharePoint 2010中托管元数据 SharePoint 2010中的客户端模型 SharePoint 2010中的Content Query WebPart
WF4:自定义跟踪参考者
生鱼片 · 2011-01-24 · via 博客园 - 生鱼片

在前一篇文章http://www.cnblogs.com/carysun/archive/2011/01/23/WF4-ETW.html中我们讲到了WF4中的ETW跟踪参考者,这个是WF4给我们提供好的,我们可以看下该类的结构体系:

clip_image002

EtwTrackingParticipant是继承自TrackingParticipant类的,如果我们要自定义自己的跟踪参考者同样我们也是继承该类,只要重写相应的方法就可以,我们自定义一个跟踪参考者将Workflow的信息写到文件当中:

public class TxtFileTrackingParticipant:TrackingParticipant

    {

        string fileName = "";

        protected override void Track(TrackingRecord record, TimeSpan timeout)

        {

            fileName = @"c:\" + record.InstanceId + ".txt";

            using (StreamWriter sw = File.AppendText(fileName))

            {

                sw.WriteLine("----------Begin Tracking----------");

                sw.WriteLine(record.ToString());

                sw.WriteLine("----------End Tracking----------");

            }

        }

    }

我们简单的设计一个工作流,然后再将该TxtFileTrackingParticipant加到工作流的扩展点中,代码如下:

class Program

    {

        static void Main(string[] args)

        {

            //ETW tracking setup

            TrackingProfile trackingProfile = new TrackingProfile();

            trackingProfile.Queries.Add(new WorkflowInstanceQuery

            {

                States = { "*"}

            });

            trackingProfile.Queries.Add(new ActivityStateQuery

            {

                States = { "*" }

            });

            trackingProfile.Queries.Add(new CustomTrackingQuery

            {

               ActivityName="*",

               Name="*"

            });

            TxtFileTrackingParticipant txtFileTrackingParticipant = new TxtFileTrackingParticipant();

            txtFileTrackingParticipant.TrackingProfile = trackingProfile;

            AutoResetEvent autoResetEvent=new AutoResetEvent(false);

            WorkflowApplication workflowApplication = new WorkflowApplication(new Workflow1());

            workflowApplication.Completed = (arg) => { autoResetEvent.Set(); };

            workflowApplication.Extensions.Add(txtFileTrackingParticipant);

            workflowApplication.Run();

            autoResetEvent.WaitOne();

        }

    }

然后我们运行工作流,工作流完成后我们会看到跟踪信息已经记录到文本文件中如下:

clip_image004

你可以用类似的方式将工作流的跟踪信息记录到你需要的媒介中。