- Debug and Debugger classes are used to programatically control the debugging of code.
- .NET Runtime considers these classes only when program is built in Debug mode.
- Debugger.Log( ) static method logs a given message to a target. For that, we need to confirgure the Listeners collection of the Trace object. (overloads define the target which could be a File, Output Window, etc)
- Debugger class provides only two useful methods, namely Break( ) and Log( )
- To have more control over debugging, we may use Debug class.
- Debug.Assert( ) evaluates a given condition and if it is false breaks into the debugger and displays a given message.
- The following methods send messages to the output window with difference only in either formatting or in use of conditions: Write( ), WriteLine( ), WriteIf( ), WriteLineIf( ).
- The Print( ) method, however, sends message only to any attached Trace Listeners.
- DebuggerBrowsable attribute over any member of class would determine its visibility in the Debug window whenever a breakpoint is set. (It is supported only in C#.NET)
- DebuggerDisplay attribute determines how particular members of a class will be shown when an object is displayed in the Debug window. This method is used to decorate a class.
- DebuggerHidden attribute tells the debgger to ignore the lines of code that it decorates.
- DebuggerStepThrough attribute tells the debugger to Step Over the code it decorates. (This will save time for code that we are sure won't cause problems)
- DebuggerVisualizer attribute is new in .NET 2.0
- Trace class is implemented both in Debug and Release builds.
- DefaultTraceListener is attached to the output window.
- TextWriterTraceListener can redirect trace messages to a text file or Stream. (which is mentioned in the constructor)
- XmlWriterTraceListener directs Trace or Debug information to a TextWriter or Stream object. However, the file will contain XML as ouput rather than plain text as in the above listener. (XML indeed contains more information than plain text)
- XmlWriterTraceListener is new in .NET 2.0. If no filename is specified in constructor, CLR uses a GUID to create a filename.
- EventLogTraceListener directs messages to an EventLog specified in the constructor.
- DelimitedListTraceListener works the same as the above two but can use a delimiter to seperate entries.
- All of the above listeners may be configured either by using code or the configuration file.
Sunday, July 26, 2009
Chapter 10-Lesson 2
Labels:
Breakpoints,
Debug,
Debug.Assert( ),
Debugger,
Debugging,
Instrumentation,
Listeners,
Trace
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment