Search code examples
c#azureasp.net-coreazure-webapps

ASP.NET Core on Azure Web Apps, adding Azure Web App Diagnostics throws FileNotFoundException on startup


We deploy a ASP.NET Core 3.0 web application to Azure Web Apps. In order to get log messages we want to use Azure Web Apps diagnostics. We add the logging provider in program.cs:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureLogging(logging => logging.AddAzureWebAppDiagnostics())
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        });

However, on application startup, a FileNotFoundException is logged to stdout (for details and a stack trace see below) and the application fails to start (Status code 500.30).

We have taken the following steps to find the reason, but up to now, we were not successful:

  • We have used Kudu and asserted that the directory exists. The settings.json file in the directory mimics the settings we have set in log configuration.
  • In addition, we have added a call to Directory.Exists in program.cs to verify that the directory exists. This also returned true.
  • We have recreated the Azure Web App with the same name in the same app service plan with the same settings; the application fails to start.
  • In a newly created ASP.NET Core 3.0 project, we set up logging successfully, even after we mirrored some specifics of the larger solution; we verified that the following characteristics do not keep the test app from logging successfully:
    • Run from package was not set at first (we deployed the test app directly from Visual Studio), but we created a build process that deploys a package with Run from package set. So the general build and release process is identical.
    • We copied the web.config from the larger project (that was adjusted to save the log messages to stdout)
    • We copied the contents of program.cs between the projects, so that the code that creates the web host is identical.

Does anyone know a reason for this behavior or some other steps that we can use to get more details?


Exception details

Unhandled exception. System.IO.FileNotFoundException: Error reading the D:\home\site\diagnostics\ directory.

at System.IO.FileSystemWatcher.StartRaisingEvents()

at System.IO.FileSystemWatcher.StartRaisingEventsIfNotDisposed()

at System.IO.FileSystemWatcher.set_EnableRaisingEvents(Boolean value)

at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.TryEnableFileSystemWatcher()

at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken(String filter)

at Microsoft.Extensions.FileProviders.PhysicalFileProvider.Watch(String filter)

at Microsoft.Extensions.Configuration.FileConfigurationProvider.<.ctor>b__1_0()

at Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration1..ctor(Func1 changeTokenProducer, Action`1 changeTokenConsumer, TState state)

at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)

at Microsoft.Extensions.Configuration.FileConfigurationProvider..ctor(FileConfigurationSource source)

at Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build(IConfigurationBuilder builder)

at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()

at Microsoft.Extensions.Logging.AzureAppServices.SiteConfigurationProvider.GetAzureLoggingConfiguration(IWebAppContext context)

at Microsoft.Extensions.Logging.AzureAppServicesLoggerFactoryExtensions.AddAzureWebAppDiagnostics(ILoggingBuilder builder, IWebAppContext context)

at Microsoft.Extensions.Logging.AzureAppServicesLoggerFactoryExtensions.AddAzureWebAppDiagnostics(ILoggingBuilder builder)

at sevacation.Program.<>c.b__1_0(ILoggingBuilder logging) in D:\a\1\s\sevacation\Program.cs:line 22

at Microsoft.Extensions.Hosting.HostingHostBuilderExtensions.<>c__DisplayClass5_0.b__1(ILoggingBuilder builder)

at Microsoft.Extensions.DependencyInjection.LoggingServiceCollectionExtensions.AddLogging(IServiceCollection services, Action`1 configure)

at Microsoft.Extensions.Hosting.HostingHostBuilderExtensions.<>c__DisplayClass5_0.b__0(HostBuilderContext context, IServiceCollection collection)

at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()

at Microsoft.Extensions.Hosting.HostBuilder.Build()

at sevacation.Program.Main(String[] args) in D:\a\1\s\sevacation\Program.cs:line 17


Solution

  • There seems to be a current issue with .zip deployment (as of Dec. 2019)

    Try to use a different deployment method, like WebDeploy, Git, etc.