Blog Home  Home Feed your aggregator (RSS 2.0)  
.Net Jonesie - Tracing & Web Apps
A simple programmers blog
 
# Thursday, February 09, 2006
I've been looking at some complex code that someone else wrote lately and trying to figure out how it all works (or doesn't actually).  I've been adding lots of Trace statements so I can more easily follow the flow of execution.
 
Now, I'm not sure if this is a problem for anyone else or just my addled brain but I found that Trace statements in my Web Service don't display in the Visual Studio Output window unless I step into the Web Service code from the WinForms client.  This is a real drag.  All I want to do is execute the application and later examine the process steps.
 
A simple workaround is to use the TextWriterTraceListener.  With this I can capture Trace output to a file and look at the results after execute.  You do this by adding the following section to your web.config:
 
<system.diagnostics>
 <
trace autoflush="true" indentsize="2"
>
  <
listeners
>
   <
add name="myListener"  type="System.Diagnostics.TextWriterTraceListener" initializeData="mywebapp.log"
/>
  </
listeners
>
 </
trace
>
</
system.diagnostics>
 
 
However, I also rediscovered that by default, Trace messages also get output via OutputDebugStr() and this can be viewed with a suitable Debug Viewer.  Eg:
 
 
This DebugView is free from SysInternals.com.  It captures Trace messages from .Net apps and any other apps that use OutputDebugStr(), which includes Windows.  There is one problem that I noticed immediately though.  Trace.Write() appears like Trace.WriteLine() so you may loose some of the nice formatting that you would get in a log file but I can live with this.
Thursday, February 09, 2006 9:19:04 AM (New Zealand Daylight Time, UTC+13:00)  #    Comments [0]   General | Visual Studio  | 
Comments are closed.
Copyright © 2012 Peter G Jones. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: