I am looking at a file with the following code:
[..] FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = @"C:\"; watcher.Filter = "t.log"; watcher.Changed += new FileSystemEventHandler(watcher_Changed); watcher.EnableRaisingEvents = true; private static void watcher_Changed(object sender, FileSystemEventArgs e) { Console.WriteLine("Changed!"); } [..]
It works. Now suppose the content if the t.log file is:
row 1 row 2 row 3 row 4
When I add (and save) a couple of lines to the file, and the file becomes the following:
row 1 row 2 row 3 row 4 row 5 row 6
How can I get the added lines to be "line 5" and "line 6"?
Remember that a file can be very large, so having its contents in memory and creating a difference from the new version is not an option. Similarly, saving the value of the last line of reading and counting from this point on is also impossible, since this would make me read the entire file every time, plus there may be lines with the same value.
Any help is really appreciated.
source share