码迷,mamicode.com
首页 > Web开发 > 详细

.NET 4.5里的EventSource类的使用

时间:2014-10-14 21:54:47      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   使用   ar   for   sp   

EventSource类:

这个类是在.NET 4.5新推出的一个类,用来提供创建事件用于 Windows 事件跟踪的功能 (ETW)。在之前如果要配置一个Event Tracing for Windows是比较繁琐的:

http://msdn.microsoft.com/en-us/magazine/cc163437.aspx

但是在.NET 4.5之后,微软推出了这个新类,大大的简化了创建一个ETW的难度。

这个类文档上就有如何使用的例子,很简单:

 class Program
    {
        static void Main(string[] args)
        {
      //这里是触发记录事件的地方,你可以些在你需要的地方 MinimalEventSource.Log.Load(
1, "This is a test message"); } }
  //这个类就相当于以前的Provider了
sealed class MinimalEventSource : EventSource {
    //你要记录的事件的类型,你可以随便写多少个
public void Load(long ImageBase, string Name) { WriteEvent(1, ImageBase, Name); } public static MinimalEventSource Log = new MinimalEventSource(); }

但是有个问题,这些数据被会被存储到呢。怎么看呢????

在网上一同一通search后终于找到了一篇相关的blog:

http://blogs.msdn.com/b/vancem/archive/2012/07/09/logging-your-own-etw-events-in-c-system-diagnostics-tracing-eventsource.aspx

可以用PerfVIew

一句简单的命令行:

PerfView /OnlyProviders=*MinimalEventSource runeventSourceDemo.exe

然后就会在PerfView里看到一个以那个继承了EventSource的字类的为名的provider.

 

.NET 4.5里的EventSource类的使用

标签:style   blog   http   color   os   使用   ar   for   sp   

原文地址:http://www.cnblogs.com/fred-bao/p/4024554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!