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?