How to intercept debugging information (Debugview style) in C #?

For testing purposes, I’m going to build a small application that will listen to a specific event coming from the application and interact with it at that moment.

Given that we are at a point in the testing process where changing the application code is out of the question, it would be ideal from my point of view to listen to the debug trace from the application, a bit like debugview, and answer that.

Can anyone suggest a guide on how best to do this?

+3
source share
2 answers

How I found this used Microsoft's Mdbg tools to give me access from the runtime to basic debugging information. The basic form of the code used is as follows:

MDbgEngine mg; MDbgProcess mgProcess; try { mg = new MDbgEngine(); mgProcess = mg.Attach(debugProcess.Id); } catch (Exception ed) { Console.WriteLine("Exception attaching to process " + debugProcess.Id ); throw (ed); } mgProcess.CorProcess.EnableLogMessages(true); mgProcess.CorProcess.OnLogMessage += new LogMessageEventHandler(HandleLogMessage); mg.Options.StopOnLogMessage = true; mgProcess.Go().WaitOne(); bool running = true; Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress); while (running) { try { running =mgProcess.IsAlive; mgProcess.Go().WaitOne(); } catch { running = false; } } 

It seems to work quite well for me, in any case, perhaps it will provide a useful template for everyone who ends up in the same boat.

+4
source

Is the application you want to track using standard System.Diagnostics tracing? In this case, you can create your own TraceListener .

+1
source

All Articles