<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to consume ETW events from C#</title><link>http://blogs.msdn.com/danielvl/archive/2009/02/02/how-to-consume-etw-events-from-c.aspx</link><description>In my previous post I explained how to collect ETW events from URL Rewrite (or any other IIS provider) and then display those structured events in the Event Viewer. Now I want to show you how to collect ETW events using C#. The .NET Framework 3.5 provides</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: How to consume ETW events from C#</title><link>http://blogs.msdn.com/danielvl/archive/2009/02/02/how-to-consume-etw-events-from-c.aspx#9407339</link><pubDate>Sun, 08 Feb 2009 22:47:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9407339</guid><dc:creator>logus2k</dc:creator><description>&lt;p&gt;Daniel,&lt;/p&gt;
&lt;p&gt;Thank you for this article.&lt;/p&gt;
&lt;p&gt;I'm trying to use EventProviderTraceListener to publish to ETW infrastructure and then read those events from managed code. I still couldn't run your code to test if could use it to a general purpose publisher (instead of only IIS), it always gives me an &amp;quot;access denied&amp;quot; message when I try to run it.&lt;/p&gt;
&lt;p&gt;I'm also having some difficulty understanding what can/should I do programmatically to receive the events from an ETW session )and how can I create one from code). &lt;/p&gt;
&lt;p&gt;I understand there is no current official support to reading ETW events from managed code...? Is there something else I can use?&lt;/p&gt;
&lt;p&gt;Thanks in advance for your help,&lt;/p&gt;
&lt;p&gt;Ant&amp;#243;nio Cruz&lt;/p&gt;
</description></item><item><title>re: How to consume ETW events from C#</title><link>http://blogs.msdn.com/danielvl/archive/2009/02/02/how-to-consume-etw-events-from-c.aspx#9422485</link><pubDate>Sat, 14 Feb 2009 23:28:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9422485</guid><dc:creator>Daniel Vasquez Lopez</dc:creator><description>&lt;p&gt;I updated the post to add another example that includes support for custom events.&lt;/p&gt;
&lt;p&gt;This is only for Vista/Windows 2008. Make sure to the consumer application with Administrative privileges.&lt;/p&gt;
&lt;p&gt;1. Compile everything.&lt;/p&gt;
&lt;p&gt;2. Run Producer.exe (it uses EventProviderTraceListener)&lt;/p&gt;
&lt;p&gt;3. From command line (as Admin), run 'logman start MySession -p {13D5F7EF-9404-47ea-AF13-85484F09F2A7} -ets'&lt;/p&gt;
&lt;p&gt;4. Open 'Reliability and Performance Monitor' and change the stream mode, in MySession's properties, from File to Real Time.&lt;/p&gt;
&lt;p&gt;5. Run Consume.exe&lt;/p&gt;
&lt;p&gt;6. Type something in the Producer.exe and press &amp;lt;Enter&amp;gt;&lt;/p&gt;
&lt;p&gt;Expected: Consume[r].exe should echo what you typed in Producer.exe&lt;/p&gt;
&lt;p&gt;When you are done, run 'logman stop MySession -ets' to stop the custom ETW session.&lt;/p&gt;
&lt;p&gt;The events produced by EventProviderTraceListener doesn't have any schema, so what I did was to take the UserData 'as is' and convert it to string (be aware that this is just a guess, the data could not be a string).&lt;/p&gt;
&lt;p&gt;Hope this helps &lt;/p&gt;
</description></item><item><title>re: How to consume ETW events from C#</title><link>http://blogs.msdn.com/danielvl/archive/2009/02/02/how-to-consume-etw-events-from-c.aspx#9426894</link><pubDate>Tue, 17 Feb 2009 05:08:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9426894</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Thanks so much for sharing this library! &amp;nbsp;&lt;/p&gt;
&lt;p&gt;I'm using it to consume ETW output from SQL Server 2008 Extended Events, and have hit a couple of issues:&lt;/p&gt;
&lt;p&gt;A) The event names do not appear to be populating. &amp;nbsp;If I dump the ETL file they are there, so I assume it would be in the real time output as well?&lt;/p&gt;
&lt;p&gt;B) Any chance it can be extended to be a bit more flexible with regard to non-top level properties? &amp;nbsp;For example the trace I'm working with right now sends back 11 top level properties and two non-top level properties (I'm not sure of the right term for &amp;quot;non-top level&amp;quot;) -- these are just Unicode strings, so no difficulties with maps, etc. &amp;nbsp;I tried to modify the code to consume them and wound up with all sorts of garbage data; I suspect the pointers are not correct...&lt;/p&gt;
&lt;p&gt;I'm happy to send you an example of how to set this up if you're interested in seeing what I'm talking about. &amp;nbsp;Drop me a line at amachanic [at] gmail [dot] com ... it would be great to get this thing fully working so I hope so :-)&lt;/p&gt;
&lt;p&gt;Either way, thanks again!&lt;/p&gt;
</description></item><item><title>re: How to consume ETW events from C#</title><link>http://blogs.msdn.com/danielvl/archive/2009/02/02/how-to-consume-etw-events-from-c.aspx#9447543</link><pubDate>Fri, 27 Feb 2009 01:26:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9447543</guid><dc:creator>walkerc</dc:creator><description>&lt;p&gt;Hello Daniel,&lt;/p&gt;
&lt;p&gt;I am using the EventTraceWater class to consume KernelTrace Events.&lt;/p&gt;
&lt;p&gt;I backed the class into .Net 2.0 by replacing ReaderWriterLockSlim with ReaderWriterLock.&lt;/p&gt;
&lt;p&gt;The class functions flawlessly on Vista64, on Windows7 (32 bit, build 7000) it ... , on XP 32 bit, &lt;/p&gt;
&lt;p&gt;int error = NativeMethods.ProcessTrace(array, 1, IntPtr.Zero, IntPtr.Zero); in ProcessTraceInBackground fails.&lt;/p&gt;
&lt;p&gt;I have not been able to find a documented reason for this failure since ProcessTrace is supported on XP.&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/aa364093"&gt;http://msdn.microsoft.com/en-us/library/aa364093&lt;/a&gt;(VS.85).aspx&lt;/p&gt;
&lt;p&gt;Any ideas? &lt;/p&gt;
&lt;p&gt;I was also considering unwrapping ProcessTraceInBackground out of a delegate and using the entire class from a background thread in order to simplify the code and perhaps reduce failure modes that way. Your thoughts?&lt;/p&gt;
&lt;p&gt;Again thanks for the class, hopefully this functionality will make it to the framework sooner rather than later.&lt;/p&gt;
</description></item><item><title>re: How to consume ETW events from C#</title><link>http://blogs.msdn.com/danielvl/archive/2009/02/02/how-to-consume-etw-events-from-c.aspx#9447547</link><pubDate>Fri, 27 Feb 2009 01:29:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9447547</guid><dc:creator>walkerc</dc:creator><description>&lt;p&gt;Sorry, I forgot I left a statement hanging:&lt;/p&gt;
&lt;p&gt;on Windows7 (32 bit, build 7000) it ...&lt;/p&gt;
&lt;p&gt;I was waiting for the error to occur again to be more specific, the class runs for a while and then throws a NullReference exception, just FYI. I don't have a dev environment on Win 7 yet to debug.&lt;/p&gt;
</description></item><item><title>re: How to consume ETW events from C#</title><link>http://blogs.msdn.com/danielvl/archive/2009/02/02/how-to-consume-etw-events-from-c.aspx#9447566</link><pubDate>Fri, 27 Feb 2009 01:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9447566</guid><dc:creator>walkerc</dc:creator><description>&lt;p&gt;One final question, really I promise.&lt;/p&gt;
&lt;p&gt;I noticed that &lt;/p&gt;
&lt;p&gt;_logFile.EventRecordCallback = EventRecordCallback;&lt;/p&gt;
&lt;p&gt;in StartTracing, was not using a delegate. Would using a delegate here provide some benefit?&lt;/p&gt;
&lt;p&gt;I apologize if this seems ignorant, even though I have been programming for 30 years, my C# is pretty shabby. &lt;/p&gt;
</description></item><item><title>re: How to consume ETW events from C#</title><link>http://blogs.msdn.com/danielvl/archive/2009/02/02/how-to-consume-etw-events-from-c.aspx#9451517</link><pubDate>Sun, 01 Mar 2009 04:00:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9451517</guid><dc:creator>walkerc</dc:creator><description>&lt;p&gt;OK, new years resolution, become more familar with code before commenting on it...&lt;/p&gt;
&lt;p&gt;1) _logFile.EventRecordCallback = EventRecordCallback; is using a delegate.&lt;/p&gt;
&lt;p&gt;2) int error = NativeMethods.ProcessTrace(array, 1, IntPtr.Zero, IntPtr.Zero); in ProcessTraceInBackground &amp;nbsp;&lt;/p&gt;
&lt;p&gt;blocks. &lt;/p&gt;
&lt;p&gt;It does not matter if EventTraceWatcher.enabled (and in turn, StartTracing and NativeMethods.ProcessTrace is called from a separate external thread or as originally implemented.&lt;/p&gt;
&lt;p&gt;3) ProcessTrace still fails in XP and reason is still a mystery to me.&lt;/p&gt;
</description></item><item><title>re: How to consume ETW events from C#</title><link>http://blogs.msdn.com/danielvl/archive/2009/02/02/how-to-consume-etw-events-from-c.aspx#9463131</link><pubDate>Fri, 06 Mar 2009 20:30:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9463131</guid><dc:creator>dixi</dc:creator><description>&lt;p&gt;An extraordinary and very useful piece of work. Congrats Daniel. I noticed that some people are having troubles with the class in Win7. Actually, I have been troubles with ETW in Win7. It happens that the same .NET 3.5 code I developed works seamlessly in WS2008 but not in Win7. The Beta I gues? Anyway, still trying...&lt;/p&gt;
</description></item><item><title>re: How to consume ETW events from C#</title><link>http://blogs.msdn.com/danielvl/archive/2009/02/02/how-to-consume-etw-events-from-c.aspx#9474736</link><pubDate>Sat, 14 Mar 2009 08:26:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9474736</guid><dc:creator>Daniel Vasquez Lopez</dc:creator><description>&lt;p&gt;Thank you dixi for your comments, I haven't test it in Windows 7, but I will give it a try as soon as I can.&lt;/p&gt;
&lt;p&gt;WalkerC, unfortunately this code won't work for XP, I'm using the field ProcessTraceMode and callback EventRecordCallback &lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/aa363780"&gt;http://msdn.microsoft.com/en-us/library/aa363780&lt;/a&gt;(VS.85).aspx that are not available prior Windows Vista.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
</description></item><item><title>Consume IIS ETW tracing</title><link>http://blogs.msdn.com/danielvl/archive/2009/02/02/how-to-consume-etw-events-from-c.aspx#9618788</link><pubDate>Fri, 15 May 2009 19:00:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9618788</guid><dc:creator>Eok's Blog</dc:creator><description>&lt;p&gt;Event Tracing for Windows (ETW) is wonderful mechanism to monitor, log and trouble shoot of your application&lt;/p&gt;
</description></item></channel></rss>