Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I attach an EventListener to an EventSource in another process?

I'm trying to attach a listener to a running process which uses an EventSource to trace processing events. I've gotten as far as creating my own listener by inheriting from EventListener and (presumably) need to call EnableEvents to begin receiving information.

The first argument to all the overloads is the EventSource to configure and send messages from, but I am unclear how to compose that instance when it needs to identify a source of events in the external process.

I'm just knocking this together as a proof-of-concept, so the code runs in a Console application and the TestEventListener just tries to write the event to the Console window.

EventSource source = null;

using (var listener = new TestEventListener())
{
    listener.EnableEvents(source, EventLevel.Verbose);

    Console.ReadKey();
}
like image 657
Paul Turner Avatar asked Sep 24 '13 10:09

Paul Turner


1 Answers

Unfortunately, the EventListener class does not talk cross-process, or even across AppDomains. That wasn't the purpose of the EventListener class.

Instead, I recommend you use the upcoming (and most likely will be the official supported ETW "reader" library from MSFT) --

http://www.nuget.org/packages/Microsoft.Diagnostics.Tracing.TraceEvent

While you're at it, check out -- http://oculus.codeplex.com/ (this is very similar to TraceEvent, but has a bunch of different generate code special windows events)

like image 51
mjsabby Avatar answered Oct 03 '22 07:10

mjsabby