Skip to content

Latest commit

 

History

History
74 lines (52 loc) · 2.79 KB

troubleshoot.md

File metadata and controls

74 lines (52 loc) · 2.79 KB
title author description monikerRange ms.author ms.custom ms.date uid
Troubleshoot ASP.NET Core Blazor Hybrid
guardrex
Learn how to troubleshoot issues in ASP.NET Core Blazor Hybrid with BlazorWebView logging.
>= aspnetcore-8.0
riande
mvc
02/09/2024
blazor/hybrid/troubleshoot

Troubleshoot ASP.NET Core Blazor Hybrid

xref:Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView has built-in logging that can help you diagnose problems in your Blazor Hybrid app.

This article explains the steps to use xref:Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView logging:

  • Enable xref:Microsoft.AspNetCore.Components.WebView.Maui.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 xref:Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView and related components under the xref:Microsoft.AspNetCore.Components.WebView?displayProperty=fullName 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 xref:Microsoft.Extensions.Logging?displayProperty=fullName:

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.

[!INCLUDE]

Register the provider inside the call to xref:Microsoft.Extensions.DependencyInjection.LoggingServiceCollectionExtensions.AddLogging%2A added in the previous step by calling the xref:Microsoft.Extensions.Logging.DebugLoggerFactoryExtensions.AddDebug%2A 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