C#: tail like program for text file

前端 未结 4 803
后悔当初
后悔当初 2020-12-30 11:18

I have a log file that continually logs short lines. I need to develop a service that reacts (or polls, or listens to) to new lines added to that file, a sort of unix\' tail

4条回答
  •  长情又很酷
    2020-12-30 11:39

    I would recommend using FileSystemWatcher to be notified of changes to the file or files you're concerned about. From there, I would cache information such as the size of the file between events and add some logic to only respond to full lines, etc. You can use the Seek() method of the FileStream class to jump to a particular point in the file and read only from there. Given these features, it shouldn't be too hard to hand-roll this functionality if that's what you need.

提交回复
热议问题