Modus Operandi
Modus Operandi

Reputation: 641

Can't set ASP.NET Core console logging below Information

I can't seem to get any Debug or Trace statements displayed in console.

In Startup.cs Configure(...) I have:

loggerFactory
    .WithFilter(
        new FilterLoggerSettings
        {
            {"AssetTrader", LogLevel.Debug},
            {"Microsoft", LogLevel.Warning},
            {"System", LogLevel.Warning},
        })
    .AddConsole();

In the controller action I have:

this._logger.LogTrace("Trace");
this._logger.LogDebug("Debug");
this._logger.LogInformation("Info");
this._logger.LogWarning("Warn");

But the console output only shows the two entries:

info: AssetTrader.Controllers.HomeController[0]
  Info
warn: AssetTrader.Controllers.HomeController[0]
  Warn

I have also tried simply loggerFactory.AddConsole(LogLevel.Debug), same result.

Gist of a simple test project to reproduce the issue: https://gist.github.com/modo-lv/66e3209f89e986423397928630ba5f9a

Upvotes: 2

Views: 2361

Answers (1)

Modus Operandi
Modus Operandi

Reputation: 641

Solved, thanks to Tseng's comment and answer here.

In my case, removing

loggerFactory
    .WithFilter(
        new FilterLoggerSettings
        {
            {"AssetTrader", LogLevel.Debug},
            {"Microsoft", LogLevel.Warning},
            {"System", LogLevel.Warning},
        })
    .AddConsole();

from Configuration(..) and adding

services.AddLogging(
    builder =>
    {
        builder.AddFilter("AssetTrader", LogLevel.Debug)
            .AddFilter("Microsoft", LogLevel.Warning)
            .AddFilter("System", LogLevel.Warning)
            .AddConsole();
    });

to ConfigureServices(...) solved the problem.

Upvotes: 2

Related Questions