IMO, it would be better to reorganize the existing code, replacing the existing one Console.WriteLinewith some central method in your code, and then repeat this method, presumably providing another TextWriter:
private static TextWriter output = Console.Out;
public static TextWriter Output {
get {return output;}
set {output = value ?? Console.Out;}
}
public static void WriteLine(string value) {
output.WriteLine(value);
}
public static void WriteLine(string format, params string[] args) {
output.WriteLine(format, args);
}
Or (simpler and less hacky re static field), just pass it TextWriterinto your existing code and write to it?
source
share