title: How to configure .NET Core Azure logging
body: <p>I have uploaded a very simple app in Azure on .NET Core 2.1.3.<br>
  Configured the App Service logging as follows:
  <a href="https://i.stack.imgur.com/xQR1R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xQR1R.png" alt="enter image description here"></a></p>
  
  <p>the code:</p>
  
  <pre><code>public class Program
  {
      public static void Main(string[] args)
      {
          CreateWebHostBuilder(args).Build().Run();
      }
  
      public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
              .UseStartup&lt;Startup&gt;();
  }
  
  public class Startup
  {
      private readonly ILogger&lt;Startup&gt; logger;
      public Startup(IConfiguration configuration, ILogger&lt;Startup&gt; logger)
      {
          this.Configuration = configuration;
          this.logger = logger;
      }
  
      public IConfiguration Configuration { get; }
  
  
      // This method gets called by the runtime. Use this method to add services to the container.
      // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
      public void ConfigureServices(IServiceCollection services)
      {
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
  
          // Commented lines doesn't affect ...              
          //loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
          // loggerFactory.AddDebug();
          Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
  
          loggerFactory.AddAzureWebAppDiagnostics();
  
          this.logger.LogInformation("Loading::::::::::::::::::");
  
  
          app.Run(async (context) =&gt;
          {
              this.logger.LogInformation("OnRequest::::::::::::::::::");
              await context.Response.WriteAsync("Loading...");
          });
      }
  }
  </code></pre>
  
  <p>The problem is that the logging works locally, but no in azure. If I open <code>/Log Files/Application/afg4322-201809062011.log</code> my messages <code>OnRequest::::::::::::::::::</code> and <code>Loading::::::::::::::::::</code> didn't appear there. Currently the logic catches all requests and simply writes a log message.<br>
  Also I've installed <code>Microsoft.Extensions.Logging.AzureAppServices</code> and troubleshot <a href="https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/azure-apps/troubleshoot?view=aspnetcore-2.1#aspnet-core-module-stdout-log" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/azure-apps/troubleshoot?view=aspnetcore-2.1#aspnet-core-module-stdout-log</a> nothing working. </p>
  
  <p>How to log a message in Azure app ? Maybe I'm missing some simple setting?</p>
  
  <p>The <code>applicationSettings.json</code>:</p>
  
  <pre><code>{
    "Logging": {
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Information"
      },
      "Console": {
        "IncludeScopes": "true"
      }
    }
  }
  </code></pre>
  
  <p>I've checked this articles
  - <a href="https://stackoverflow.com/questions/40398453/asp-net-core-azure-web-app-logging">Asp.net Core azure web app logging</a>
  - <a href="https://stackoverflow.com/questions/46996730/how-to-enable-application-logs-in-azure-for-net-core-2-app">How to enable Application Logs in Azure for Net Core 2 App?</a></p>
  
  <p>I'm trying to avoid suggestion from <code>Ilya Chernomordik</code> where he says to set <code>&lt;aspNetCore stdoutLogEnabled="true" /&gt;</code> and modify <code>SourceSwitch</code>. I think it's not the correct solution.</p>