Read last line from txt file
Hi all - tried looking for this in the forums but the search kept crashing - probably this end but there you are so sorry if this has been answered before.
I need to be able to read the last line of a text log file - a bit like the Unix 'tail -f'. I'm using FileSystemWatcher which works well. There's more to it than that and more complexity to the app, and I have everything working fine except this bit. I've tried googling for it but I can't get any of the examples work properly. Can anyone point me in the right direction? Any help Much appreciated.
Re: Read last line from txt file
I found one that works, but come up against the usual problem of not being able to read a file that's open for editing by another program - is there a way around that?
Re: Read last line from txt file
show us the code you're using
Re: Read last line from txt file
Code:
Dim fs As FileStream = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
It works ok on some logs but not others and throws an exception. I don't thing the logs I'm trying to monitor are opened exclusively but they can be written to at up to 10Hz at times, and others may go several minutes with no entries.