Search code examples
asp.net-core.net-coreasp.net-core-mvckestrel-http-serverweboptimizer

Removing Responding from memory cache messages form info log level


ASP.NET Core 5 MVC application uses Weboptimizer (https://github.com/ligershark/WebOptimizer) in Debian linux.

In startUp.cs I have:

    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddWebOptimizer();
        ...
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    { 
        ...
        app.UseWebOptimizer();
        ...
    }

syslog contains large number of information messages like

Apr 18 09:12:26 c202-76 kestrel-store[28711]: #033[40m#033[32minfo#033[39m#033[22m#033[49m: WebOptimizer.AssetMiddleware[1000]

Apr 18 09:12:26 c202-76 kestrel-store[28711]: Request started for '/css/siteerp.css' Apr 18 09:12:26 c202-76 kestrel-store[28711]: #033[40m#033[32minfo#033[39m#033[22m#033[49m: WebOptimizer.AssetBuilder[1001]

Apr 18 09:12:26 c202-76 kestrel-store[28711]: Responding from memory cache for '/css/siteerp.css'

Apr 18 09:12:26 c202-76 kestrel-store[28711]: #033[40m#033[32minfo#033[39m#033[22m#033[49m: WebOptimizer.AssetMiddleware[1000]

Apr 18 09:12:26 c202-76 kestrel-store[28711]: Request started for '/lib/jquery/jquery.js'

Apr 18 09:12:26 c202-76 kestrel-store[28711]: #033[40m#033[32minfo#033[39m#033[22m#033[49m: WebOptimizer.AssetBuilder[1001]

How to disable those messages for WebOptimizer only to make log more compact? I havent found any documentation about log config.

Default appsettings.json is used:

{

  "AllowedHosts": "*",
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }

  }
}

Solution

  • This seems to be logged from the WebOptimizer namespace (I checked the source on github) which should make it easy to filter out using appsettings. Just add a "WebOptimizer" key and set it to only show "Warning" and higher.

    {
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft": "Warning",
          "Microsoft.Hosting.Lifetime": "Information",
          "WebOptimizer": "Warning"
        }
      }
    }