I am using the following procedure to attempt to read the most recent line in the www and ftp log files (\winnt\system32\Logfiles\W3SVC1\) but the catch statement reports the file is cannot be read because it is in use by another process. I assume this other process is IIS, but notepad and other file reading utilities can read these files fine. How can I accomplish the same in .NET?
private string LastFileLine (System.IO.FileInfo fi)
{
string LastLine = "";
try
{
System.IO.StreamReader sr = System.IO.File.OpenText(fi.FullName);
string line;
while ((line = sr.ReadLine()) != null)
{
LastLine = line;
}
sr.Close();
}
catch (Exception ex)
{
LastLine=ex.Message;
}
return LastLine;
}
Thanks in advance,
Troy