While debugging, I like to watch my log file as it gets filled in just like the linux command tail -f does. In a few C# lines, we are able to “watch” a file and print the changes to the console as they are made :
|
|
public static void StartReading(string path)
{
s_file = path;
s_watcher = new FileSystemWatcher();
s_watcher.Path = Path.GetDirectoryName(path);
s_watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
s_watcher.Filter = "*.txt";
s_watcher.Created += OnChanged;
s_watcher.Changed += OnChanged;
s_watcher.EnableRaisingEvents = true;
} |
Then all you need to do is print the differences each time the event is raised.