开发者

Can I output Trace messages to a separate window in Visual C# 2008 Express?

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 h开发者_运维百科ave 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜