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?

6
  • If you control the code, why do you need to hook into DebugView? Why not simply paste the date to your winform controls? Commented Jan 25, 2015 at 15:00
  • I am using this as a concept to hook into another service but need to prove it will work :-) Commented Jan 25, 2015 at 15:02
  • So you want the debug stream of another process? Commented Jan 25, 2015 at 15:10
  • Well it is a windows service and I just want to read the debug output of it. Commented Jan 25, 2015 at 15:11
  • Does this do what you want? Commented Jan 25, 2015 at 15:13

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

8 Comments

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?
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.
Another option is to take a look at the Microsoft.Samples.Debugging namespace, where you can find information here or here
I think the MDbgProcess is declared in that namespace.
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!!! :-)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.