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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

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

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x