M Yil
M Yil

Reputation: 967

ASP.NET Core 3.1 Logs not showing on Azure Service Log Stream

I have created an ASP.NET Core 3.1 application. The application is deployed to a Azure App Service. In the project I make use of logging, but the problem is that I can't view the logs on Azure via Log Stream.

Below is how I configured it:

        public static void Main(string[] args)
    {
        var host = CreateHostBuilder(args).Build();
        var logger = host.Services.GetRequiredService<ILogger<Program>>();
        logger.LogInformation("The application has started");
        host.Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureLogging((context, logging) => {
                    logging.AddConfiguration(context.Configuration.GetSection("Logging"));
                    logging.AddConsole();
                    logging.AddDebug();
                    logging.AddAzureWebAppDiagnostics();
            })
            .ConfigureServices(serviceCollection => serviceCollection
                .Configure<AzureFileLoggerOptions>(options =>
                {
                    options.FileName = "azure-diagnostics-";
                    options.FileSizeLimit = 50 * 1024;
                    options.RetainedFileCountLimit = 5;
                })
                .Configure<AzureBlobLoggerOptions>(options =>
                {
                    options.BlobName = "log.txt";
                }))
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
}

This should work right? When I go to Log Stream I should be able to see all the logs? If so, why don't I see any of the logs I created?

I don't what is happening in my code and I need the logs.

Upvotes: 3

Views: 1822

Answers (1)

Monika Reddy
Monika Reddy

Reputation: 973

In Azure App Service, your code looks good , but just ensure that you have enabled Application Logging.

enter image description here

Please find out more info regarding the same here -

  • Enable Application logging

    • Save the logs to the filesystem. This setting will only stay enabled for 12 hours
    • You can also save the logs to Azure Blob Storage, even if you also save the logs to the file system
    • Additionally, you can specify a verbosity level for the application logging to catch. This allows you to filter the logging information captured to Error, Warning, Information or Verbose. The Verbose value will catch all information that you log
  • Enable Web server logging

    • You can save the logs to either the filesystem or to Azure Blob Storage.
  • If you save to the filesystem

    • You can optionally enter a maximum size for the log files (the Quota)
    • You can optionally enter a number of days that web server logs should be retained. By default, web server logs are retained indefinitely
  • Enable Detailed Error messages

    • These are saved to the filesystem by default
  • Enable Failed request tracing

    • These are also saved to the filesystem by default

For more info : please look at this doc reference.

Upvotes: 3

Related Questions