Logging on WebAssembly seems to ignore LogLevels lower than Information

I’m testing ILoggers in a Blazor WASM application because I’d like to see Debug logs when I enable them. I tried changing the appsettings file to set the Default loglevel but it seems the only the logs from Information and upwards are showed on console.

My current appsettings.json file look like this:

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.BrowserConsole" ],
    "WriteTo": [
      { "Name": "BrowserConsole" }
    ],
    "MinimumLevel": {
      "Default": "Debug"
    }
  }
}

And this is how I’m setting the logger:

Log.Logger = new LoggerConfiguration()
    .ReadFrom.Configuration(builder.Configuration)
    .CreateLogger();

Inside of the Index.razor page I have a foreach that it’s being used to log various messages using a different level.

foreach (var level in Enum.GetValues(typeof(LogLevel)).Cast<LogLevel>())
{
    Logger.Log(level, level.ToString());
}

Using Serilog is not a must, I’ll even settle for just the default logger but I want to have the certainty that modifying the file and lowering the LogLevel I’ll see even the other logs.

What am I getting wrong?

I already tried:

  • manually settings minimum loglevel on the Program.cs;
  • separating appsettings file and putting the configuration on a appsettings.Development.json file;
  • using Serilog instead of default logger.

It is like it is, because this is what the doc says:

On the server, logging only occurs to the server-side .NET console in the Development environment at the LogLevel.Information level or higher.

So, you wont be able to see Debug level logs in WebAssembly.
And if you want to ask why they did that, the answer is:

This is done to prevent spamming the console with too much debug information, and for sure also for security reasons.

Leave a Comment