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

1

6

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();
}
Sophrosyne answered 24/9, 2013 at 10:54 Comment(0)
D
7

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)

Diane answered 29/10, 2013 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.