Search code examples
c#filesystemwatchernas

C# FileSystemWatcher not firing on Nas file system when making change from different computer


I got multiple computer (centos) mounting a NAS file system (Apsara File Storage). Then I'm using the c# FileSystemWatcher to monitor file create/update changes. The FileSystemWatcher event only fire when changes maked by the computer which runing the program itself. ps. I've tried .netcore3.1 and .net5 version.

This is my setup.

           ... 
           using var watcher = new FileSystemWatcher(dir);
           watcher.NotifyFilter = NotifyFilters.Attributes
                             | NotifyFilters.CreationTime
                             | NotifyFilters.DirectoryName
                             | NotifyFilters.FileName;

            watcher.Created += OnCreated;
            watcher.Deleted += OnDeleted;

            watcher.Filter = "*.log";
            watcher.IncludeSubdirectories = true;

            watcher.InternalBufferSize = 8192 * 8;
            watcher.EnableRaisingEvents = true; 
            ....

Solution

  • There is plenty of questions on this site that discuss FileSystemWatcher reliability and the conclusion is always the same: it is not reliable.

    The article from Peter Meinl Tamed FileSystemWatcher describes the limitations in great detail and also provides a more reliable solution.