Thursday, July 3, 2008

.NET Debug TRACE Listener

  • The Debug and Trace classes are two of the primary tools developers can use to examine the execution of their applications while they run.
  • The Write, WriteLine, WriteIf, and WriteLineIf methods all can be used to send output to attached listener objects.
  • The Assert method of the Debug and Trace classes is one mechanism to test a condition of your code and receive feedback based on that evaluation.
  • Listener objects are used as receptacles for Debug and Trace information.
  • If no listener object is specified, the DefaultTraceListener is used.
  • The XmlTraceListener can be used to output detailed information in XML format.
  • The TraceSource class allows the developer to specify information about the source of the trace information
  • The TraceSwitch allows the developer to manipulate virtually every aspect of the TraceSource class.

You can use the following questions to test your knowledge of the information in Lesson 2, "Debugging and Tracing." The questions are also available on the companion CD if you prefer to review them in electronic form.


Answers

Answers to these questions and explanations of why each answer choice is right or wrong are located in the "Answers" section at the end of the book.

1.

You need to ensure that the trace from one logical operation is isolated from that of other operations. How do you accomplish this objective?

  1. Use the CorrelationManager object to keep each trace isolated.

  2. Use a TraceSwitch to change the process's trace information.

  3. Use a different TraceLevel for each process.

  4. Specify a Correlation object, and use the CorrelationManager to control each instance of the correlation.

Image from book

2.

To use a specific visualizer object for a given class, which attribute should be used?

  1. DebuggerDisplayAttribute

  2. DebuggerVisualizerAttribute

  3. DebuggerStepThroughAttribute

  4. Use the DebuggableAttribute

Image from book

Answers

1.

Correct Answer: A

  1. Correct: The primary function of the CorrelationManager is to keep the identities unique.

  2. Incorrect: Although a TraceSwitch can be used to modify trace information, using it in this context would not accomplish the required task and would only serve to convolute the logic.

  3. Incorrect: Specifying a different TracelLevel for each process will change the output of the traces, but it will do nothing to keep them logically separated.

  4. Incorrect: Although the CorrelationManager is used to accomplish the desired results, there is no Correlation object that can be managed with it.

2.

Correct Answer: B

  1. Incorrect: The DebuggerDisplayAttribute will not specify a visualizer.

  2. Correct: The DebuggerVisualizerAttribute is the only attribute that can specify a visualizer.

  3. Incorrect: The DebuggerStepThroughAttribute is used to step over code and has no bearing on what visualizer is used.

  4. Incorrect: The DebuggableAttribute will not attach a visualizer.

No comments: