1

I published a basic asp.net core app to Azure experimenting with Serilog but it gives me a 500 error after publishing. When I comment out the RollingFile Sink it publishes fine without error. Any reason why this might be happening? Also it works fine on my local machine.

      public Startup(IHostingEnvironment appEnv)
      {
        Log.Logger = new LoggerConfiguration()
            .MinimumLevel.Information()
          //.WriteTo.RollingFile(Path.Combine(appEnv.WebRootPath, "log-{Date}.txt"), retainedFileCountLimit: 5)              
            .CreateLogger();
      }
Benjamin
  • 77
  • 1
  • 6

1 Answers1

1

It's possible for env.WebRootPath to be null. In that case, Path.Combine() will (AFAIK) throw an ArgumentNullException, which would account for the 500 errors.

Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101
  • Yes that was it thanks! I changed it to Directory.GetCurrentDirectory() instead of WebRootPath – Benjamin Jan 06 '17 at 00:58
  • 2
    %home%\LogFiles is usually where you'd want to drop in logs on App Service. You could try catch around it and default to Directory.CurrentDirectory() when not in Azure, or better still use an Application Setting and check its value (true = running on App Service, or something like that). – evilSnobu Jan 06 '17 at 07:02