C# 将第三方dll的日志重定向到自己的日志文件
在我的C程序中,我打算捕获每个可能的日志,如下所示:C# 将第三方dll的日志重定向到自己的日志文件,c#,.net,dll,apache-fop,C#,.net,Dll,Apache Fop,在我的C程序中,我打算捕获每个可能的日志,如下所示: public static void Main(string[] args) { using (new ConsoleToFile("./output.log")) { doMain(args, parser, options, directConsole); } } ConsoleToFile是这一经典文件: public class ConsoleToFile : IDisposable { pri
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
}
关于在我的代码中生成的输出,这工作得很好
但是我也包含了我用IKVM生成的apache.fop中的fop.dll
问题是:
此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吗?一种简单的方法是在命令行myapp.exe>logfile.txt中使用重定向来运行应用程序。您能让每个人都使用内置的.Net日志/跟踪基础设施吗?DLL是:由IKVM传输到DLL的原始ApacheFopJAR。按照上所述的普通方法完成。@sinlaw:1。不幸的是,我无法控制应用程序的调用方式。2.这种方法在这里不起作用:-{在我的机器上测试}