I am using Filehelpers to read a log file. To be on safe side, I want to make sure that it does not throw "File Already in use" error. There might be a remote chance that the cleanup of the log writer might still be going on when the log parsing process launches.
I am using filehelpers "ReadFileAsDT" method and passing it the file name.
I went through the source code and found that it is opening the file in read only mode which is right.
var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, FileOptions.SequentialScan);
this.Init(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize);
But still, just to be sure I kept the log file open in the excel. And ran the log parser. And it gave the "File in use error".
If I keep the file open in Notepad, Wordpad or Notepad++, this error is not coming.
Is there anything special with the way the excel opens the files?
Excel maintains an active read/write lock on the file. This is true for ANY file that it opens and prevents other applications from reading/writing them half the time.
Personally, if you want to have the log file open at the same time, use notepad, wordpad or my personal favourite, as it has a lot of advanced functions like reloading of files when they change, TextPad.