See Trace Listeners .
DefaultTraceListener will be written to the output window. To send messages to TraceListener, you just need to call Trace.WriteLine("my output string"); .
// C
EDIT: In response to your comment, the following code will print βmy output lineβ immediately before βPress enter to quitβ in the console window:
static void Main(string[] args) { Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); Trace.WriteLine("my output string"); Console.Write("Press enter to quit"); Console.ReadLine(); }
EDIT2: After reading your question again, I realized that you were specifically trying to use TraceSource , in which case you just need to configure the switch so that it knows what level of trace events should be sent to the console window. Try adding this after adding listeners:
SourceSwitch sourceSwitch = new SourceSwitch("SourceSwitch", "Verbose"); t.Switch = sourceSwitch;
source share