debugger class

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hi!

This example was found in a book. It will write the text "This is my test"
to the output that can be found under the View menu alternative.
Trace.Listeners.Clear();
DefaultTraceListener myListener = new DefaultTraceListener();
Trace.Listeners.Add(myListener);
System.Diagnostics.Debugger.Log(1, "Test", "This is my test");

I made a little test here so I removed all rows and kept just this one
System.Diagnostics.Debugger.Log(1, "Test", "This is my test");
and I get the same result.

Does the Debugger has a Listener by default ?

//Tony
 
Tony Johansson said:
This example was found in a book. It will write the text "This is my test"
to the output that can be found under the View menu alternative.
Trace.Listeners.Clear();
DefaultTraceListener myListener = new DefaultTraceListener();
Trace.Listeners.Add(myListener);
System.Diagnostics.Debugger.Log(1, "Test", "This is my test");

I made a little test here so I removed all rows and kept just this one
System.Diagnostics.Debugger.Log(1, "Test", "This is my test");
and I get the same result.

Does the Debugger has a Listener by default ?

I believe that you are mistaking the System.Diagnostics.Debugger class
for the System.Diagnostics.Debug class. The former has a "Log" method that
posts a message to the attached debugger (and does not use the
TraceListener). The latter has a "Write" method that *does* use the
TraceListener.
 
This example was found in a book. It will write the text "This is my test"
to the output that can be found under the View menu alternative.
Trace.Listeners.Clear();
DefaultTraceListener myListener = new DefaultTraceListener();
Trace.Listeners.Add(myListener);
System.Diagnostics.Debugger.Log(1, "Test", "This is my test");

I made a little test here so I removed all rows and kept just this one
System.Diagnostics.Debugger.Log(1, "Test", "This is my test");
and I get the same result.

Does the Debugger has a Listener by default ?

The Debugger doesn't have listeners at all; the Trace class does. From MSDN
(Trace.Listeners property):

=============
The listeners produce formatted output from the trace output. By default,
the collection contains an instance of the DefaultTraceListener class.
=============
 
Back
Top