2

I have a c# windows service outputting the current date and time every second using Debug.WriteLine():

Debug.WriteLine(DateTime.Now);

I am then able to read this output using the SysInternals DebugView program (https://technet.microsoft.com/en-us/sysinternals/bb896647) however I want to basically recreate what I see in this tool in my own winforms application, therefore how can you programatically grab exactly the info DebugView is?

Apqu
  • 4,880
  • 8
  • 42
  • 68

1 Answers1

2

Basically you want to intercept the debugging information coming from some process?

I think that this SO question might help you, but I don't know what is the current state of the MDbg.

I have a little program that does something like this, but I do it using interprocess communication with Named Pipes, so there is a 2-way communication involved.

You could also take a look at the Listeners property, which you can redirect the debug output to another stream, if it's somehow useful.

[Edit1]:

This SO thread tells you were to download the MDbg API so you can use it within .NET applications. Then the other link I posted might help you to actually get the output.

I think this problem can be tricky to solve, I solved it using NamedPipes but then both applications (the service and some other app) had to know about each other. Simply reading the Debug.Write of a process might involve some research about the MDbg.

Community
  • 1
  • 1
Ricardo Pieper
  • 2,613
  • 3
  • 26
  • 40
  • MDbg appears to be dead so therefore would it be possible with listeners? I tried TextWriterTraceListener but it doesn't seem to get anything from the service? – Apqu Jan 25 '15 at 15:17
  • This might get tricky. Actually, there are some ways to read the debug output. First, redirect the Debug output to the Console.Out stream, but to actually read the output you should create the process within your custom debug viewer. The other option is to use Asynchronous or Named Pipes, like I did, but then you should do some changes to your service. – Ricardo Pieper Jan 25 '15 at 15:21
  • Another option is to take a look at the Microsoft.Samples.Debugging namespace, where you can find information [here](https://www.nuget.org/packages/Microsoft.Samples.Debugging.MdbgEngine/) or [here](http://stackoverflow.com/questions/6812033/where-can-i-download-microsoft-samples-debugging-net-library) – Ricardo Pieper Jan 25 '15 at 15:23
  • I think the MDbgProcess is declared in that namespace. – Ricardo Pieper Jan 25 '15 at 15:24
  • I am very close using MDbg now i believe but i get some errors with LogMessageEventHandler and Console_CancelKeyPress from the example, +1 for effort , so close to the perfect answer!!! :-) – Apqu Jan 25 '15 at 15:37
  • If you solve your problem, please let me know. I'm also interested. – Ricardo Pieper Jan 25 '15 at 15:41
  • Will do, seems really close but now failing with a COM error: The operation failed because debuggee and debugger are on incompatible platforms lol! – Apqu Jan 25 '15 at 15:52
  • This comment section is getting long, my last bet is to change your [Build Configuration](https://msdn.microsoft.com/en-us/library/kkz9kefa.aspx). Try setting both to x86 and see what happens. – Ricardo Pieper Jan 25 '15 at 16:30