I have an ASP.NET Core project running on an Azure Web App, logging to blob storage, which is full of hundreds of MB of the following:
[Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request starting HTTP/1.1
[Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executing endpoint
[Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Ro
[Information] Microsoft.EntityFrameworkCore.Infrastructure: Entity Framework Core
[Information] Microsoft.EntityFrameworkCore.Infrastructure: Entity Framework Core
[Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Ex
[Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Ex
[Information] Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor: Execu
[Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Ex
[Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executed endpoint
[Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request finished HTTP/1.1
My own logging statements (created via ILogger) are lost in the noise, how can I stop logging all this activity?
My HostBuilder looks like this:
static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.ConfigureAppConfiguration((context, config) =>
{
config.AddJsonFile("appsettings.json", optional: false);
config.AddEnvironmentVariables();
})
.ConfigureLogging((context, logging) =>
{
logging.ClearProviders();
logging.AddAzureWebAppDiagnostics();
if (context.HostingEnvironment.IsDevelopment())
logging.AddConsole();
})
My appsettings.json looks like this:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Warning"
}
},
"ConnectionStrings": {
"DefaultConnection": "Server=.\\SQLEXPRESS;Database=Blah;Integrated Security=true;MultipleActiveResultSets=True"
}
}
In development on my local PC, everything is logged to the console is as expected (i.e. Microsoft.* log messages don't appear). The appsettings.json file is apparently doing it's job because if I change "Microsoft": "Warning" to "Microsoft": "Information" all those Microsoft.* log messages (that I don't want) do appear in the console. But running in an app service on Azure, it's as if the appsettings.json file is being ignored. The call to config.AddEnvironmentVariables() is mainly to override the DefaultConnection database connection string in my appsettings.json file with the one on the Configuration page on the web app in Azure, but that page doesn't contain any log-related environment variable settings.
I just can't seem to control what's going into my logs, any advice?