在我的C#程序中,我打算捕获这样的每个潜在日志:
public static void Main(string[] args)
{
using (new ConsoleToFile("./output.log"))
{
doMain(args, parser, options, directConsole);
}
}
ConsoleToFile是这个经典之作:
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
}
关于我的代码中生成的输出,这很有效!
但是我也从apache.fop中包含了fop.dll(我用IKVM生成了它)。
问题: 这个fop-DLL注销到控制台,好像重定向不存在一样。
e.g。经典令人讨厌的警告,如:
"WARNING: padding-* properties are not applicable to fo:table-header, but a non-zero value for padding was found."
知道如何将这些日志记录重定向到我的文件“output.log”吗?