What should you do?

You have recently created an application, and want to capture all debugging text messages generated by it.
You would like these debugging messages to display on the command line. The application that you created contains the following code:
Debug.WriteLine (“Start the processing”);
Console.WriteLine (“Generated by Console.WriteLine”);
Debug.WriteLine (“End the processing”);
You need to ensure that you are able to capture all debugging messages to the command line.
What should you do?

You have recently created an application, and want to capture all debugging text messages generated by it.
You would like these debugging messages to display on the command line. The application that you created contains the following code:
Debug.WriteLine (“Start the processing”);
Console.WriteLine (“Generated by Console.WriteLine”);
Debug.WriteLine (“End the processing”);
You need to ensure that you are able to capture all debugging messages to the command line.
What should you do?

A.
Use the following code:
Debug.Listeners.Add (new TextWriterTraceListener(Console.Out));
Debug.AutoFlush = true;

B.
Use the following code:
Debug.Listeners.Add (new StreamWriter(Console.Out));
Debug.AutoFlush = true;

C.
Use the following code:
Debug.Listeners.Add (new ConsoleTraceListener());
Debug.AutoFlush = true;

D.
Use the following code:
Debug.Listeners.Add (new DefaultTraceListener());
Debug.AutoFlush = true;

Explanation:
Listeners are used to capture trace and debug messages. Both the Trace and Debug objects share the same Listeners collection, which includes a DefaultTraceListener
that will capture trace and debug messages in the Output window. You are able to override this behavior by using the Add method to add another listener to the Listeners collection.
The ConsoleTraceListener is used to route trace and debug messages to the console. The AutoFlush property should be set to true for immediate capture. This specifies that after each message is written, the buffer is flushed and the output is written to the listener.
Incorrect Answers:
A: You should use the code that instantiates a TextWriterTraceListener object that specifies the Console’s output stream because this is less efficient than specifying a ConsoleTraceListener object.
B: You should use the code that instantiates a StreamWriter object that specifies the Console’s output stream because the Listeners collection allows only Listener object streams.
D: You should use the code that instantiates a DefaultTraceListener object because this will capture the debugging messages
to the Output window in the Visual Studio .NET 2005 IDE. Also, each Listeners collection will contain a DefaultTraceListener by default.



Leave a Reply 1

Your email address will not be published. Required fields are marked *


networkmanagers

networkmanagers

C