I have program that write its errors in text file, when this program catches error, it appends it to a text file, I want to make small program to detect errors one by one from a text file, when program write an errors.
I use this way:
string ErrorsFilePath = @"D:\A.txt"; // example path
long oldLength = 0;
long newLength = 0;
while (true)
{
FileInfo fi = new FileInfo(ErrorsFilePath);
newLength = fi.Length;
if (newLength > oldLength)
{
GC.Collect();
string txtAllErrors = File.ReadAllText(ErrorsFilePath);
int startIndex = (int)oldLength;
int length = (int)(newLength - oldLength);
ErrorDetected(txtAllErrors.Substring(startIndex, length));
oldLength = newLength;
}
Thread.Sleep(10);
GC.Collect();
}
Are there a way to detect text file changes on its content?, Like events fires when text file changes, and give me the different text changes.