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

推荐订阅源

博客园 - 【当耐特】
Help Net Security
Help Net Security
P
Proofpoint News Feed
J
Java Code Geeks
爱范儿
爱范儿
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
Google DeepMind News
Google DeepMind News
H
Help Net Security
G
Google Developers Blog
Jina AI
Jina AI
Vercel News
Vercel News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
Lohrmann on Cybersecurity
S
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
IT之家
IT之家
Security Archives - TechRepublic
Security Archives - TechRepublic
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic
GbyAI
GbyAI
B
Blog
O
OpenAI News
博客园_首页
Cisco Talos Blog
Cisco Talos Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News: Ask HN
Hacker News: Ask HN
TaoSecurity Blog
TaoSecurity Blog
腾讯CDC
MongoDB | Blog
MongoDB | Blog
M
MIT News - Artificial intelligence
C
Cybersecurity and Infrastructure Security Agency CISA
Cyberwarzone
Cyberwarzone
Webroot Blog
Webroot Blog
Simon Willison's Weblog
Simon Willison's Weblog
Y
Y Combinator Blog
C
Cisco Blogs
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
AI
AI
W
WeLiveSecurity
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
Blog — PlanetScale
Blog — PlanetScale

博客园 - 生鱼片

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

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