0

I've tried various attempts at getting logging to show in Azure, but nothing is working. My latest attempt was this:
https://ardalis.com/configuring-logging-in-azure-app-services/

I added this to my project:
https://www.nuget.org/packages/Microsoft.Extensions.Logging.AzureAppServices

In Programs.cs, I did this:

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

And I have this line in an API controller method that gets called:

_logger.LogWarning("Test warning logging.");

I also tried logging this way:

Trace.TraceWarning("Test warning logging (trace).");

My Azure App Service Logs settings look like this:

enter image description here

Yet, when I go to log stream, there are never any messages:

enter image description here

I'm at a lost as to what to try next.

4
  • The log stream interface is, to be excessively polite, cantankerous - but you should see at least something there, if it's actually working. Maybe try refreshing the log interface in the azure portal to see if anything appears, and then look for your own log messages? With a log level of verbose you should be seeing lots of stuff. Commented Jun 7, 2020 at 0:02
  • I see logging in "Web Server logs," but not "Application logs." But even though I see logging, I don't see my log messages. Commented Jun 7, 2020 at 0:27
  • @BobHorn, is it a .net core 3.1 project or other version of .net core like 2.2 etc.? Commented Jun 7, 2020 at 8:40
  • @IvanYang It's .NET Core 3.0. Commented Jun 7, 2020 at 13:40

1 Answer 1

1

In your Programs.cs, the ConfigureLogging(logging=>{xxx}) should not be placed within ConfigureWebHostDefaults. You should use the following code in your Programs.cs:

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

Then I'm using this line of code to send logs:

_logger.LogInformation("this is an information from index page...");

Then in azure portal, the message is there:

enter image description here

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.