// Keep track of the original output writer TextWriter originalOut = Console.Out; // Override console output with a custom one StringWriter buf = new StringWriter(); Console.SetOut(buf); Console.WriteLine("This will be captured!"); // Capture output! buf.Flush(); string capturedOutput = buf.ToString(); // Restore original output writer Console.SetOut(originalOut);