views:

397

answers:

3

I'm not sure if this is possible in the manner I am envisioning or not so I'm hoping someone can help me wrap my head around this.

I'm wanting to inject a TraceListener into a running process - kind of. I don't actually care how I attach to the process, but the end goal is to listen to the trace output of the running process and dump it out to a console window.

I can attach to the process okay, and I can write a TraceListener okay... where I'm coming unstuck is the bit in the middle. Anyone got any clue if this can be done? If so, can you give me a push in the right direction because I can't see the forest for the trees here.

Maybe I'm trying to approach this in the wrong way?

+2  A: 

I don't think this is practical. It would be easy to create a listener at runtime, but that is something the App has to do, it involves adding something to a list.

You may want to make sure the Default listener isn't removed and use an OutputDebug tool to listen in.

Henk Holterman
Interesting - and that just attaches to the Default Listener? That will save me an immense amount of time. I was thinking I'd have to write something myself - but if someone's already done the work for me, there's no point in reinventing the wheel.
BenAlabaster
Yes, the default listener uses the OutputDebugString API (WIN32). It is what shows up in the Visual Studio debugger.
Henk Holterman
A: 

When I want to view debug output, I use a combination of log4net and DebugView. I can make log4net monitor a configuration file to allow me to change the log4net logging level at runtime, or I can use filters in DebugView.

Don Kirkby
If I'm using log4net, I can just as easily use a tracelistener. The purpose is trying to attach to an already running application without taking it down.
BenAlabaster
I don't know as much about trace listeners, but log4net can monitor a configuration file to let you adjust the logging level without taking down the application. DebugView just monitors all processes that write to the OutputDebugString API call in Windows. You don't attach to a specific process, but you can filter.
Don Kirkby
interesting, thanks, I'll look into that
BenAlabaster
+1  A: 

Would DbgView from Sysinternals be enough for your needs? It will show you the trace messages of all running processes without having you to configure a trace listener prior to starting the process.

0xA3
Is there a mono version of DbgView? I want to use DbgView when i'm doing mono work in OSX, so debugview doesnt work!
phsr