Debug-level configuration not respected by logger in blazor wasm
See original GitHub issueTo reproduce
- Create a new Blazor WASM project.
$ dotnet new blazorwasm -o logger-repro
- Create a
wwwroot/appsettings.json
file with the following contents:
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
}
}
- Create a
wwwroot/appsettings.Development.json
file with the following contents:
{
"Logging": {
"LogLevel": {
"Default": "Trace"
}
}
}
- Add package reference to
logger-repro.csproj
:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<UseBlazorWebAssembly>true</UseBlazorWebAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-preview.7.20365.19" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0-preview.7.20365.19" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0-preview.7.20364.11" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="5.0.0-preview.7.20364.11" />
</ItemGroup>
</Project>
- Setup logging in
Program.cs
by adding the following line:
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
- Add a set of logging statements to the Counter component.
@page "/counter"
@using Microsoft.Extensions.Logging
@inject ILogger<Counter> logger;
<h1>Counter</h1>
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
logger.Log(LogLevel.Critical, "This is critical.");
logger.Log(LogLevel.Error, "This is error.");
logger.Log(LogLevel.Warning, "This is warning.");
logger.Log(LogLevel.Information, "This is info.");
logger.Log(LogLevel.Debug, "This is debug.");
logger.Log(LogLevel.Trace, "This is trace.");
currentCount++;
}
}
- Run the app and observe that when you click the increment button the critical, error, warning, and information log levels are displayed. Although the log level is set to trace the debug and trace messages are missing.
To ensure that the environment is correct and the correct log level is loaded in the configuration, I added this two lines to the Program.cs
file:
Console.WriteLine(builder.HostEnvironment.Environment);
Console.WriteLine(builder.Configuration.GetValue<string>("Logging:LogLevel:Default"));
It also looks like the app is crashing…
Environement:
$ dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.100-preview.7.20366.6
Commit: 0684df3a5b
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.100-preview.7.20366.6\
Host (useful for support):
Version: 5.0.0-preview.7.20364.11
Commit: 53976d38b1
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Blazor WebAssembly Logging is not honoring ...
You can try to use this Nuget package In my project it logs Debug messages as well when correctly configured. It works always...
Read more >ASP.NET Core Blazor logging
This article explains Blazor app logging, including configuration and how to write log messages from Razor components.
Read more >Blazor WebAssembly - Changing The Log Level At Runtime
Learn how to change the log level of your Blazor WebAssembly application at runtime for easier debugging.
Read more >Don't let ASP.NET Core Console Logging Slow your App down
x Console logging is very, very slow when it is set to Information or worse Debug . The default ASP.NET Core default if...
Read more >Relay Blazor client logs to Serilog in ASP.NET Core
Ingestion together implement a client/server log relay for Blazor apps running Serilog, feeding events from the Blazor client into the ASP.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Closing this issue since I found the cause of my problem. 🙈
For all having the same issue: Check the log level in the chrome browser console. The default setting only shows messages with a log level of info, warning and errors.
We’ve moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.