Using the Debug and Trace Classes

Team-Fly    

 
Application Development Using Visual Basic and .NET
By Robert J. Oberg, Peter Thorsteinson, Dana L. Wyatt
Table of Contents
Appendix B.  Tracing and Debugging in .NET


The useful methods and properties are shared. The overloaded WriteLine and Write are used to write debug or trace output. The overloaded WriteLineIf and WriteIf write output if the condition in their first argument is true.

 Debug.WriteLine(_    "This was compiled with a DEBUG directive!") Trace.WriteLine(_    "This was compiled with a TRACE directive!") ... Debug.WriteLineIf(DebugBooleanSwitch.Enabled, _    "Debug Boolean Switch enabled at startup.") Debug.WriteLineIf(Not DebugBooleanSwitch.Enabled, _    "Debug Boolean Switch disabled at startup.") 

Output is indented with the Indent and Unindent methods. The indentation size is controlled with the IndentSize property.

 Trace.Indent() ... Trace.IndentSize = 10 

You can also set the indentation size in the application configuration file.

 <?xml version="1.0"?> <configuration>     <system.diagnostics>  <trace indentsize="15" />  <switches>                 <add name="DebugSwitch" value = "1" />                 <add name="TraceSwitch" value = "2" />             </switches>     </system.diagnostics> </configuration> 

The Assert method can check an assertion. The AutoFlush property and the Flush method control the flushing of the output buffer.


Team-Fly    
Top
 


Application Development Using Visual BasicR and .NET
Application Development Using Visual BasicR and .NET
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 190

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net