DebugView/OutputDebugString Lives in .NET

Back in my COM+ VB6 days I always had a tough time  to
debug into my VB6 components that were running in a dllhost (COM+ Server Application
environment). Basically when the call jumped into the component that was hosted
by COM+ , it would sometimes do funny things like hang the VB6 debug session.

So one method to help debug, was to use an api in the code called OutputDebugString in addition with a little application called DBWIN32.exe, to capture and display the OutputDebugString calls in the code.   
In a nutshell DBWIN32 is a little window that captures and displays any Win32 debug output.
 
So in the VB6 COM+ component code , basically when I needed to debug something I would put in the
code:

OutputDebugString("I am debugging")

Then if the DBWIN32 window was up and running it would append to it's output:

July 7 2003 10:02:03    I am debugging


Does this work in .NET? -> Yes. But the nice thing about it is that you do not have to
use OutputDebugString API calls to add to the Win32 debug output.

Instead all I have to do is call something that I am sure you are familiar with such as:

System.Diagnostics.Debug.WriteLine("I am debugging"); or
System.Diagnostics.Trace.WriteLine("I am Tracing");

To try this out (if you haven't already, go ahead do it, you might find this useful later!) go to the following
site and download debugview :

http://www.sysinternals.com/

This is not a full blown install, but only a zip file with a little exe in it. Once you have unzipped Dbgview.exe:

1) Run Dbgview.exe. The little DebugView window will be launched.
2) Create a new .NET windows or .NET ASP application.
3) Somewhere in the code put (make sure the code is called on startup)

System.Diagnostics.Debug.WriteLine("I am debugging");
System.Diagnostics.Trace.WriteLine("I am Tracing");

4) Compile it, (but make sure that it is the debug version).
5) Run the .exe (Windows) or navigate to the URL (ASP.Net) to run the debug version.
(Note if you are in VS.NET go to menu choice Debug/Start Without Debugging or
the VS.NET Output Window will grab the debug Win32 output)
6) In the Dbgview.exe output window you should see something like:

20 3:35:37  [3476] I am debugging
20 3:35:38  [3476] I am Tracing


Why is this useful? :

1) If you have not set up a listener for your Debug or Trace output, you will
not see the debug or trace output if your are running outside the VS.NET environment.
2) This is extremely useful for Biztalk 2004 debugging , but go here to
see why :
http://blogs.msdn.com/darrenj/archive/2004/04/29/123254.aspx
3) If you are bored you can always see what else is logging Win32 debug output.
4) For other Win32 debug output listeners and discussions go here :
http://weblogs.asp.net/cszurgot/archive/2003/05/21/7368.aspx

Comments

  • matt May 27, 2004 9:31 AM

    I use OutputDebugString in my VB COM inprocess servers, but when I hosted it in COM+ no output in Dbgview.exe

    Any ideas ?

  • matt June 1, 2004 9:29 AM

    Rusty , Can I see the code you are using to output to the Win32 debug?

  • matt February 22, 2005 11:06 PM

    Thanks for sharing your knowledge on Debugview. I was wondering if we can just use one call to enable tracing instead of putting trace calls every where in the code. Like, put it in a constructor or a page load and it will trace all activity happening on that particular .aspx or .asmx page. Sure, putting trace calls everywhere is a good feature and gives the user more flexibility in debugging, but it makes a mess of the code..Any ideas?

  • matt May 13, 2006 5:47 AM

    I think you still need outdebugstringA
    if release mode if you want to log information to the debug view , it is good idea to use outdebugstring

Leave a Comment

(required) 
(optional)
(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS