From: Tony Johansson on
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


From: Alberto Poblacion on
"Tony Johansson" <johansson.andersson(a)telia.com> wrote in message
news:uCvT%23ST7KHA.420(a)TK2MSFTNGP02.phx.gbl...
> 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.

From: Jeff Johnson on
"Tony Johansson" <johansson.andersson(a)telia.com> wrote in message
news:uCvT%23ST7KHA.420(a)TK2MSFTNGP02.phx.gbl...

> 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.
=============