1

I have an ASP.NET Core 3.1 API running on Microsoft Azure App Service.

I have set up an ILogger into the app and I use it extensively to monitor the behavior of the API. I would like to be able to see those messages real time into the Azure Log Stream of the app portal.

I managed to get logs after registering the AzureWebAppDiagnostics into Program.cs as follows:

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

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

The problem is that messages I logged explicitly, using

logger.LogInformation("whatever message") 

are mixed with system messages and becomes flooded: Entity Framework commands, Microsoft.Hosting.Lifetime messages, and multiple other informative messages.

How can I set up the system in a way that I get only error/warning messages from the system, and informative messages from my app code.

I tried to change the appsettings.json as follows, but it seems to have no effect at all :

"Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Error",
      "Microsoft.Hosting.Lifetime": "Error",
      "Microsoft.*": "Error",
      "System": "Error",
      "Microsoft.EntityFrameworkCore.*": "Warning" 
    }
  }

I deleted as well the appsettings.development.json file just in case, as suggested here.

What am I doing wrong?

2 Answers 2

3

Actually, after throrough researches, the solution was provided here

You need to add AzureAppServicesBlob and AzureAppServicesFile configuration into your configuration file, they seem to be the one taken into account by the Azure Log Stream.

So I added the following part :

"AzureAppServicesBlob": {
  "LogLevel": {
    "Default": "Information",
    "Microsoft": "Error",
    "System": "Error"
  }
},
"AzureAppServicesFile": {
  "LogLevel": {
    "Default": "Information",
    "Microsoft": "Error",
    "System": "Error"
  }
}
Sign up to request clarification or add additional context in comments.

Comments

-1

It's not wildcarded in the configuration. It's simply a namespace prefix: use Microsoft.EntityFrameworkCore as the property name.

1 Comment

This is not why it's not working, I can see Hosting.Lifetime information logs despite the namespace is correct.

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.