FileSystemWatcher does not trigger on Azure

49 views Asked by At

I'm trying to find out why my FileSystemWatcher is working locally, but not when I deploy it to an Azure webapp. I have seen this question but I have not solved anything.

I try to give you more information: I am using .Net 8 and I am deploying the application on a Windows Web App with Free (F1) plan.

Here the code that should start the watcher:

public void Start()
{
    if(_watcher != null && _isRunning) 
        return;

    _pathToWatch = Path.Combine(System.IO.Directory.GetCurrentDirectory(), _folderConfiguration.RcvFolderPath);
    // Crea il watcher per la cartella rcv
    using (_watcher = new FileSystemWatcher(_pathToWatch, "*.*"))
    {
        _watcher.NotifyFilter = NotifyFilters.Attributes;

        // Registra gli eventi
        //watcher.Created += OnFileCreated; Created event non viene eseguito su azure
        _watcher.Changed += OnFolderContentChanged;

        // Abilita il watcher
        _watcher.EnableRaisingEvents = true;
        _isRunning = true;
       
        _logger.LogInformation($"FileWatcherService in ascolto sulla cartella {x}...");
        //Console.ReadLine(); // Mantieni l'applicazione in esecuzione
    }
}

_pathToWatch = Path.Combine(System.IO.Directory.GetCurrentDirectory(), _folderConfiguration.RcvFolderPath); gives me this result: "C:\\home\\site\\wwwroot\\root\\rcv"

When I connect to the web app via FTP, I see this:

enter image description here

The path seems to be ok.

Here the code should run when a new file is created in the folder:

private void OnFolderContentChanged(object sender, FileSystemEventArgs e)
{
    _logger.LogInformation($"OnFolderContentChanged: file {e.Name} creato in rcv.");
    System.IO.File.Create(Path.Combine(System.IO.Directory.GetCurrentDirectory(), _folderConfiguration.LabelFolderPath, $"xxx.txt"));     
}

Then I tried to create, delete or rename via ftp some txt file. But nothing happened.

Finally the logs:

enter image description here

I don't see any error... but I don't either see anything else than the watcher started.

Any idea please?

Thank you

0

There are 0 answers