How to write to Console.Out during execution of an MSTest test

Julian picture Julian · Feb 3, 2011 · Viewed 125.6k times · Source

Context:

Answer

Andras Zoltan picture Andras Zoltan · Feb 3, 2011

The Console output is not appearing is because the backend code is not running in the context of the test.

You're probably better off using Trace.WriteLine (In System.Diagnostics) and then adding a trace listener which writes to a file.

This topic from MSDN shows a way of doing this.


According to Marty Neal's and Dave Anderson's comments:

using System;
using System.Diagnostics;

...

Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
// or Trace.Listeners.Add(new ConsoleTraceListener());
Trace.WriteLine("Hello World");