public static String CaptureError(Action Action, bool Capture = true)
{
if (Capture)
{
var OldOut = Console.Error;
var StringWriter = new StringWriter();
try
{
Console.SetError(StringWriter);
Action();
}
finally
{
Console.SetError(OldOut);
}
try
{
return StringWriter.ToString();
}
catch
{
return "";
}
}
else
{
Action();
return "";
}
}