Results 1 to 4 of 4

Thread: Read last line from txt file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2011
    Posts
    27

    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.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Jul 2011
    Posts
    27

    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?

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Read last line from txt file

    show us the code you're using

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2011
    Posts
    27

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width