How can I stop logs generated by AspNetCore?

Eric P 5 Reputation points

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) =>
        .ConfigureWebHostDefaults(webBuilder =>
        .ConfigureAppConfiguration((context, config) =>
            config.AddJsonFile("appsettings.json", optional: false);
        .ConfigureLogging((context, logging) =>
            if (context.HostingEnvironment.IsDevelopment())

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?

A set of technologies in the .NET Framework for building web applications and XML web services.
3,588 questions
A set of technologies in the .NET Framework for building web applications and XML web services.
1,643 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
5,668 questions
{count} vote

1 answer

Sort by: Most helpful
  1. ajkuma 17,746 Reputation points Microsoft Employee

    @Eric P , Apologies for the delay from over the weekend.

    From your issue description, I understand you're wanting to stop the logs generated.
    Just to highlight, in App Service, you can set app settings outside of your app code.

    If you configure an app setting with the same name in App Service and in appsettings.json, for example, the App Service value takes precedence over the appsettings.json value. The local appsettings.json value lets you debug the app locally, but the App Service value lets you run the app in production with production settings.
    Also, connection strings work in the same way. This way, you can keep your application secrets outside of your code repository and access the appropriate values without changing your code.

    When deployed to Azure App Service, the app uses the settings in the App Service logs section of the App Service page of the Azure portal.

    The default location for log files is in the D:\\home\\LogFiles\\Application folder, and the default file name is diagnostics-yyyymmdd.txt. The default file size limit is 10 MB, and the default maximum number of files retained is 2.
    Please check this doc section for config info: Azure App Service

    Please let us know, I'll follow-up with you further.

    0 comments No comments