好的,我正在尝试使用Tail来监视日志文件,但我无法通过编程获得与使用相同参数通过cmd提示符手动运行它时相同的行为。
当通过cmd提示符运行时,它会显示新行
立即
.不过从程序上讲,我得等一下
75+条新线路
在日志文件中,在“缓冲区”释放所有行之前。
这是我现在的代码。
private const string tailExecutable = @"C:\tail.exe";
private const string logFile = @"C:\test.log";
private static void ReadStdOut()
{
var psi = new ProcessStartInfo
{
FileName = tailExecutable,
Arguments = String.Format("-f \"{0}\"", logFile),
UseShellExecute = false,
RedirectStandardOutput = true
};
// Running same exe -args through cmd.exe
// works perfectly, but not programmatically.
Console.WriteLine("{0} {1}", psi.FileName, psi.Arguments);
var tail = new Process();
tail.StartInfo = psi;
tail.OutputDataReceived += tail_OutputDataReceived;
tail.Start();
tail.BeginOutputReadLine();
}
static void tail_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
}
我以前使用过OutputDataReceived事件,但从未遇到过这些缓冲/垃圾邮件问题。
我现在很困惑。
*
编辑
*
我发现了
this wintail project on CodeProject
我将切换到那个,因为缓冲区使这个解决方案太慢了。
谢谢你的回答。