Ok, I am trying to use Tail to monitor a log file, but I cannot get the same behavior programatically as when I manually run it through cmd prompt using the same parameters.
When run through cmd prompt it displays the new lines instantly. Programatically though, I have to wait for about 75+ new lines in log file before the 'buffer' unleashes all the lines.
Here's the code I have now.
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);
}
I have used the OutputDataReceived event before but never had these buffering/spamming problems.
I am so confused with about right now.
* Edit *
I found this wintail project on CodeProject and am going to be switching to that because the buffer makes this solution way too slow.
Thanks for the answers.