/// <summary> /// Intercept console out and error and write to both the current out /// and error and the TextWriter object that is passed into the method. /// </summary> /// <param name="twConsole">A TextWriter to which to write in addition /// to what console out and error are currently set.</param> private void InterceptConsole(TextWriter twConsole) { _savedConsoleOut = Console.Out; _savedConsoleError = Console.Error; var consoleOutMultiplexer = new TextWriterMultiplexer(); consoleOutMultiplexer.AddTextWriter(_savedConsoleOut); consoleOutMultiplexer.AddTextWriter(twConsole); var consoleErrorMultiplexer = new TextWriterMultiplexer(); consoleErrorMultiplexer.AddTextWriter(_savedConsoleError); consoleErrorMultiplexer.AddTextWriter(twConsole); Console.SetOut(consoleOutMultiplexer); Console.SetError(consoleErrorMultiplexer); }