Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Both Debug and Trace are used to output additional messages beyond normal error logging for your application. What is output is up to the programmer. Typical things that may be written are method entries/exits, method argument values, method return values, configuration information that is being used, critical performance timings etc.</p> <p>The main difference between Debug and Trace is that Trace is present in release builds while Debug is not. I find Trace to be more useful as it allows you to get additional information about the functioning of your application in a production environment (assuming you added Trace to begin with). One thing to consider when adding Trace messages is to think about information that you would like to have access to if a tricky production issue popped up. </p> <p>Both Debug and Trace are conditionally compiled. Debug (by default) is compiled into debug builds while Trace (by default) is compiled into release builds. The conditional compilation is determined by the compilation flags (for Trace: /d:TRACE) or preprocessor directives (for Trace: #define TRACE).</p> <p>The good thing is that these statements can benefit you during development but can easily be removed for production builds by changing a compile flag.</p> <p><strong>Output</strong></p> <p>To get at the output of a Trace requires a trace listener. There is a default trace listener called (not surprisingly) <code>DefaultTraceListener</code>. The <code>DefaultTraceListener</code> sends the Trace messages to shared memory (via the Win32 <code>OutputDebugString</code> method). </p> <p>OK, but how do you see those trace messages? </p> <p>The easiest way is to run a program to read the information for you. <a href="http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx" rel="noreferrer">DebugView</a> is the de facto standard to do that. Pretty much just start it up and the messages start appearing.</p> <p>You can also direct the output to other locations using the <code>TextWriterTraceListener</code> or <code>EventLogTraceListener</code>.</p> <p>You can also add trace listeners via configuration:</p> <pre><code>&lt;configuration&gt; &lt;system.diagnostics&gt; &lt;trace autoflush="false" indentsize="4"&gt; &lt;listeners&gt; &lt;add name="myListener"type="System.Diagnostics.TextWriterTraceListener"initializeData="TextWriterOutput.log" /&gt; &lt;remove name="Default" /&gt; &lt;/listeners&gt; &lt;/trace&gt; &lt;/system.diagnostics&gt; &lt;/configuration&gt; </code></pre> <p><br> If you are already using a logging provider (e.g. Enterprise Library, log4net) then you may want to look at using their approach since they almost always provide similar conditional logging functionality. However, they may not provide functionality similar to <code>Assert</code> or <code>WriteIf</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload