0

I have a very very basic c# question about logging debug-trace messages on console. For redirecting the trace message to console, we can use

    Trace.Listeners.Add(new ConsoleTraceListener());

I was expecting something similar to exist for logging debug message to console.

    //Debug.Listeners.Add(new ConsoleDebugListener()); //does not exist
    Debug.Listeners.Add(new ConsoleTraceListener());

so the name does not make a difference or am i missing something.

EDIT

I just wanted to know if something like ConsoleDebugListener or something similar exist or not. it works with trace listener though.

2
  • It works for me. Are you definitely running a DEBUG build of the console app? Commented Aug 29, 2014 at 10:18
  • i know it works... why question is, why something similar does not exist for debug listner. Commented Aug 29, 2014 at 10:20

1 Answer 1

1

The ConsoleTraceListener is a class that handles how to write messages coming its way; even though it contains Trace it is not the exclusive output method for the Trace class in the System.Diagnostics namespace.

If you want to really find why the ConsoleTraceListener works for both Debug and Trace, it is because both of them use the TraceInternal class internally, which then sends messages to the listeners it contains. Maybe that's a good enough reason for the initial listeners to have been called *Trace* (EventLogTraceListener, XmlWriterTraceListener, etc...)

Interestingly, listeners are shared between Debug and Trace since they both return the TraceInternal property.

Sign up to request clarification or add additional context in comments.

1 Comment

great. thanks a lot. I was just little curious, nothing else. something works, but if it has a little quirk, wanted to find out why. thanks a lot for detailed answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.