How to enable stdout logging for a .Net core app using run from package

To enable stdout logging for an Azure .NET Core app running from a package, follow these steps:

  1. In the Azure portal, navigate to your App Service.
  2. Go to the Configuration tab.
  3. Under the Application settings section, add or update the following settings:
  • ASPNETCORE_ENVIRONMENT: Set the value to Development or any other non-production environment name.
  • WEBSITE_RUN_FROM_PACKAGE: Set the value to 1.
  1. Under the General settings section, set Web sockets to On.
  2. Save the changes.

Next, modify your Program.cs file in your .NET Core app to configure the logger:

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

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

This configuration will enable stdout logging for your Azure .NET Core app running from a package.

Leave a comment