3

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.

1
  • Please try to refrain from begging here. While I understand the temptation to plead and cajole readers into supplying an answer, and thus relieving you of woe and suffering, that is probably not an ideal way to interact with volunteers. It's worth noting that we prefer technical writing here anyway, and questions are meant to be written for a wide future audience. Commented Sep 9, 2020 at 20:46

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.