I need to read in a rolling log file in .NET 3.5sp1. I’m wondering what’s the best way to do this? The file can get really big. An idea I had was to
- Open File
- Read file to last read line (in the first case, it was 0)
- Read all remaining lines
- Close stream and remember the last line number read.
- Wait a bit.
- Rinse/repeat.
I’m not sure if this the best way though and efficient for the memory, considering the file can be pretty huge. And I can’t have the log file being locked either 🙁
Thoughts?
Get the file length and read the last piece of the file. It won’t be hard to find the first line break and show everything from there on. FileStream has a
Lengthproperty, and thereadmethod allows you to read from one place to another.Steven is right. If the other program doesn’t require exclusive access, you can open read-only and be fine.