views:

87

answers:

2

Console, Debug, and Trace messages all seem to be displayed in the "Output" window, which is fine in most cases, but I'd like to have my Trace messages displayed separately (so they're not interleaved with everything else). Is there any way to do this without writing to a file/log?

+3  A: 

Sure, by default tracing writes to the Output window using the DefaultTraceListener, which is an implementation of the TraceListener class.

To write to a seperate output you'll need to either use one of the pre-supplied alternative TraceListeners or implement your own (handling, at a minimum, Write() and WriteLine(); then register your listener in your configuration file.

STW
I've actually done this in the past - it's very useful. However, in this case, I'm actually talking about Visual Studio's "Output" dockable window. It would be nice to monitor Console, Debug, and Trace messages separately instead of all being dumped to that one window (with assembly load and first chance exception messages in there too).
Pwninstein
Yes, so you could write a Visual Studio plugin to provide seperate windows for each--along with custom TraceListeners to send the ouput to your plugin. However, by default, the `DefaultTraceListener` writes exclusively to the `Output` window--and Visual Studio adds it to the Application's Listeners collection--so there is no point-and-click way to achieve what you want
STW
You can just 'turn off' the assembly load and first chance exception from being dumped in the debug output window. Just right click in that window and in the bottom of the pop up menu, you will see options to turn off display of exceptions and module load and unload messages.
C Johnson
+1  A: 

There is only one option available in VS to get output in a different window: Tools + Options, Debugger, General, "Redirect all Output Window text to the Immediate Window". That however is not likely to do what you want it to do.

There are no good options available to get output into a VS window. The only mechanism is the Windows OutputDebugString() API function which lets the debugger see messages. That's already being used by the DefaultTraceListener. The Visual Studio hosting process supports redirecting Console.Write/Line() output to the Output window. The mechanism by which it works is unclear to me, other than that the hosting process is a custom hosted version of the CLR. Not something you'd want tackle, assuming it is even possible to replace it.

By far the most practical approach is to simply create your own window to display trace output, using your own trace listener. Easy enough to do with a Windows Forms form class that contains a multiline TextBox. How practical that is depends on the nature of your main EXE. Or trace to a file and use a file viewer that's smart enough to see updates to the file. I use Far.

Oh, and there's SysInternals' DebugView utility. It snoops on OutputDebugString() text.

Hans Passant