In my C# program I intend to catch every potential log like this:
public static void Main(string[] args)
{
using (new ConsoleToFile("./output.log"))
{
doMain(args, parser, options, directConsole);
}
}
ConsoleToFile is this classic one:
public class ConsoleToFile : IDisposable
{
private readonly StreamWriter fileOutput;
private readonly TextWriter oldOutput;
/// <summary>
/// Create a new object to redirect the output
/// </summary>
/// <param name="outFileName">
/// The name of the file to capture console output
/// </param>
public ConsoleToFile(string outFileName)
{
oldOutput = Console.Out;
fileOutput = new StreamWriter(
new FileStream(outFileName, FileMode.Create)
);
fileOutput.AutoFlush = true;
Console.SetOut(fileOutput);
Console.SetError(fileOutput);
}
// Dispose() is called automatically when the object
// goes out of scope
#region IDisposable Members
public void Dispose()
{
Console.SetOut(oldOutput); // Restore the console output
fileOutput.Close(); // Done with the file
}
#endregion
}
Concerning output generated in my code this works well!
But I also have included the fop.dll from apache.fop (I generated it with IKVM).
The Problem: This fop-DLL logs out to console as if the redirecting wouldn't be present.
e.g. classic nasty warnings like:
"WARNING: padding-* properties are not applicable to fo:table-header, but a non-zero value for padding was found."
Any idea how to redirect also these logging to my file "output.log"?