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

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
小众软件
小众软件
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
G
Google Developers Blog
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
爱范儿
爱范儿
B
Blog
云风的 BLOG
云风的 BLOG
H
Hackread – Cybersecurity News, Data Breaches, AI and More
GbyAI
GbyAI
博客园 - 叶小钗
aimingoo的专栏
aimingoo的专栏
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
博客园_首页
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence

博客园 - 生鱼片

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

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