Troubleshoot ASP.NET Core Blazor Hybrid

BlazorWebView has built-in logging that can help you diagnose problems in your Blazor Hybrid app.

This article explains the steps to use BlazorWebView logging:

  • Enable BlazorWebView and related components to log diagnostic information.
  • Configure logging providers.
  • View logger output.

Enable BlazorWebView logging

Enable logging configuration during service registration. To enable maximum logging for BlazorWebView and related components under the Microsoft.AspNetCore.Components.WebView namespace, add the following code in the Program file:

services.AddLogging(logging =>
{
    logging.AddFilter("Microsoft.AspNetCore.Components.WebView", LogLevel.Trace);
});

Alternatively, use the following code to enable maximum logging for every component that uses Microsoft.Extensions.Logging:

services.AddLogging(logging =>
{
    logging.SetMinimumLevel(LogLevel.Trace);
});

Configure logging providers

After configuring components to write log information, configure where the loggers should write log information.

The Debug logging providers write the output using Debug statements.

To configure the Debug logging provider, add a reference to the Microsoft.Extensions.Logging.Debug NuGet package.

Note

For guidance on adding packages to .NET apps, see the articles under Install and manage packages at Package consumption workflow (NuGet documentation). Confirm correct package versions at NuGet.org.

Register the provider inside the call to AddLogging added in the previous step by calling the AddDebug extension method:

services.AddLogging(logging =>
{
    logging.AddFilter("Microsoft.AspNetCore.Components.WebView", LogLevel.Trace);
    logging.AddDebug();
});

View logger output

When the app is run from Visual Studio with debugging enabled, the debug output appears in Visual Studio's Output window.

Additional resources