简体   繁体   中英

How to detect new changes in a file?

I am trying to build a logViewer which displays log from multiple files. I want to display the new changes in the files as soon as they are modified. I am using a FileSystemWatcher to detect if a file has been changed. But I am not sure how do I detect the change that has been made in the file that I am monitoring. I have seen some of the questions in StackOverflow but they are not helpful. How do I do this?

Edit: All I want is to get the line/lines that have been added. If there are any method other than using FileSystemWatcher I am fine with that also.

Use the filesystemwatcher to detect changes and get new lines using last read position and seek the file.

https://stackoverflow.com/a/19230599/1583653

If you are looking to do this programmatically you will need to have both the previous version and the current version. Then you will have to make a comparison somehow: letter by letter, word by word, etc, and then go from there.

FileSystemWatcher only detects if the change has happened, it doesn't detect the change itself.

Besides FileSystemWatcher your task can be solved (quite efficiently) using a filesystem filter driver. With such driver you'll know about the changes right when (before or after) they are made, and you know what exactly is done.

You can write a filter yourself if you have experience with kernel-mode development or use our CallbackFilter product, though the latter is an overkill for your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM