public FileChangeWatcher(string path, WatchedFileFactory watchedFileFactory) { _path = path; _watchedFileFactory = watchedFileFactory; _watchedFiles = new Dictionary<string, WatchedFile>(); _watcher = new FileSystemWatcher(path); _watcher.EnableRaisingEvents = true; _watcher.Deleted += WatcherChanged; _watcher.Renamed += WatcherChanged; _watcher.Created += WatcherChanged; _watcher.Changed += WatcherChanged; }
public void Collect(ILogger logger) { _logger = logger; var watcherFctory = new WatchedFileFactory(LogFileChange); _watcher = new LogWatcher(watcherFctory); if (_logFileConfiguration!=null) { foreach (var directory in _logFileConfiguration.Directories) _watcher.WatchDirectory(directory.Name, directory.Filter); foreach (var file in _logFileConfiguration.Files) _watcher.WatchFile(file.Name); } }
public DirectoryChangeWatcher(string path, string filter, WatchedFileFactory watchedFileFactory) { _path = path; _watchedFileFactory = watchedFileFactory; _watchedFiles = new Dictionary<string, WatchedFile>(); foreach (var file in Directory.GetFiles(path, filter)) { _watchedFiles.Add(Path.GetFileName(file).ToLower(), _watchedFileFactory.Create(file)); } _watcher = new FileSystemWatcher(path, filter); _watcher.EnableRaisingEvents = true; _watcher.Deleted += WatcherChanged; _watcher.Renamed += WatcherChanged; _watcher.Created += WatcherChanged; _watcher.Changed += WatcherChanged; }
public LogWatcher(WatchedFileFactory watchedFileFactory) { _watchedFileFactory = watchedFileFactory; }