How can one look at .NET Debug.WriteLine traces outside the debugger?
+1
A:
Check out DebugView. I have not used this with .NET, but I have used it with VC++ apps.
Dana Holt
2009-04-21 15:44:20
dang, slow on the draw.
scottm
2009-04-21 15:45:49
It captures traces for the whole system. I'd like something I can give to another engineer and say "just use this to see the traces"; unfortunately this tool produces a lot of noise and I don't see an obvious way to filter just my app. Also unfortunate is that my app contains C++ code that also produces irrelevant traces I would like to hide - so a .NET-only trace would be nice.
Qwertie
2009-04-21 16:46:44
+1
A:
You can either use DbgView from Sysinternals or add the following to your applications config file to trace messages to the console:
<configuration>
<system.diagnostics>
<sources>
<source name="TraceTest" switchName="SourceSwitch"
switchType="System.Diagnostics.SourceSwitch" >
<listeners>
<add name="console" />
<remove name ="Default" />
</listeners>
</source>
</sources>
<switches>
<!-- You can set the level at which tracing is to occur -->
<add name="SourceSwitch" value="Warning" />
<!-- You can turn tracing off -->
<!--add name="SourceSwitch" value="Off" -->
</switches>
<sharedListeners>
<add name="console"
type="System.Diagnostics.ConsoleTraceListener"
initializeData="false"/>
</sharedListeners>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="console" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
You can also change the type of the trace listener in the log file from System.Diagnostics.ConsoleTraceListener
to any other trace listener, e.g. to log to the system's EventLog or to trace to a custom application.
0xA3
2009-04-21 15:46:57
I tried adding a <AppName>.exe.config file, with the above contents, in the same folder as my executable, but nothing happened when the program traced stuff. I also tried System.Diagnostics.TextWriterTraceListener in the config file as suggested at http://msdn.microsoft.com/en-us/library/system.diagnostics.defaulttracelistener(VS.80).aspx, which worked only if there was lots of trace data -- apparently it doesn't flush the file automatically.
Qwertie
2009-04-21 16:30:30
Follow up: autoflush="false" must be changed to autoflush="true". And it's too bad I can't get the console trace listener working. Worst of all it doesn't work on a Release build, even though I have defined TRACE!
Qwertie
2009-04-21 16:41:48
Oh I see, I have to use Trace.WriteLine instead of Debug.WriteLine for the TRACE constant to work.
Qwertie
2009-04-21 16:57:30