Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor Hybrid troubleshoot article 8.0 #30554

Merged
merged 5 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion aspnetcore/blazor/components/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ uid: blazor/components/integration
---
# Integrate ASP.NET Core Razor components into ASP.NET Core apps

<!--
<!-- UPDATE 9.0 Activate after release and INCLUDE is updated

[!INCLUDE[](~/includes/not-latest-version.md)]

-->

This article explains Razor component integration scenarios for ASP.NET Core apps, including prerendering of Razor components on the server.
Expand Down
4 changes: 3 additions & 1 deletion aspnetcore/blazor/components/prerendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ uid: blazor/components/prerender
---
# Prerender ASP.NET Core Razor components

<!--
<!-- UPDATE 9.0 Activate after release and INCLUDE is updated

[!INCLUDE[](~/includes/not-latest-version.md)]

-->

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ uid: blazor/components/render-outside-of-aspnetcore
---
# Render Razor components outside of ASP.NET Core

<!-- UPDATE 9.0 Activate after release and INCLUDE is updated

[!INCLUDE[](~/includes/not-latest-version.md)]

-->

Razor components can be rendered outside of the context of an HTTP request. You can render Razor components as HTML directly to a string or stream independently of the ASP.NET Core hosting environment. This is convenient for scenarios where you want to generate HTML fragments, such as for generating email content, generating static site content, or for building a content templating engine.

In the following example, a Razor component is rendered to an HTML string from a console app:
Expand Down
6 changes: 6 additions & 0 deletions aspnetcore/blazor/components/render-modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ uid: blazor/components/render-modes
---
# ASP.NET Core Blazor render modes

<!-- UPDATE 9.0 Activate after release and INCLUDE is updated

[!INCLUDE[](~/includes/not-latest-version.md)]

-->

This article explains control of Razor component rendering in Blazor Web Apps, either at compile time or runtime.

## Render modes
Expand Down
6 changes: 6 additions & 0 deletions aspnetcore/blazor/components/sections.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ uid: blazor/components/sections
---
# ASP.NET Core Blazor sections

<!-- UPDATE 9.0 Activate after release and INCLUDE is updated

[!INCLUDE[](~/includes/not-latest-version.md)]

-->

To control the content in a Razor component from a child Razor component, Blazor supports *sections* using the following built-in components:

* `SectionOutlet`: Renders content provided by `SectionContent` components with matching `SectionName` or `SectionId` arguments. Two or more `SectionOutlet` components can't have the the same `SectionName` or `SectionId`.
Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/blazor/fundamentals/startup.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ The module exports either or both of the following conventional functions:
* `beforeStart(options, extensions)`: Called before Blazor starts. For example, `beforeStart` is used to customize the loading process, logging level, and other options specific to the hosting model.
* Client-side, `beforeStart` receives the Blazor options (`options` in this section's examples) and any extensions (`extensions` in this section's examples) added during publishing. For example, options can specify the use of a custom [boot resource loader](xref:blazor/fundamentals/startup#load-boot-resources).
* Server-side, `beforeStart` receives SignalR circuit start options (`options` in this section's examples).
* In [`BlazorWebViews`](/mobile-blazor-bindings/walkthroughs/hybrid-hello-world#mainrazor-native-ui-page), no options are passed.
* In a [`BlazorWebView`](/mobile-blazor-bindings/walkthroughs/hybrid-hello-world#mainrazor-native-ui-page), no options are passed.
* `afterStarted`: Called after Blazor is ready to receive calls from JS. For example, `afterStarted` is used to initialize libraries by making JS interop calls and registering custom elements. The Blazor instance is passed to `afterStarted` as an argument (`blazor` in this section's example).

For the file name:
Expand Down
67 changes: 67 additions & 0 deletions aspnetcore/blazor/hybrid/troubleshoot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: Troubleshoot ASP.NET Core Blazor Hybrid
author: guardrex
description: Learn how to troubleshoot issues in ASP.NET Core Blazor Hybrid with BlazorWebView logging.
monikerRange: '>= aspnetcore-8.0'
ms.author: riande
ms.custom: "mvc"
ms.date: 10/03/2023
uid: blazor/hybrid/troubleshoot
---
# Troubleshoot ASP.NET Core Blazor Hybrid

<!-- UPDATE 9.0 Activate after release and INCLUDE is updated

[!INCLUDE[](~/includes/not-latest-version.md)]

-->

<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 two steps for this logging:

1. Enable <xref:Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView> and related components to log diagnostic information.
1. Configure a logger to write the log output to where to 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:

```csharp
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>:

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

## Configure logging output and viewing the output

After configuring components to write log information, configure where the loggers should write log information and view the log output after running the app.

The **Debug** logging providers write the output [using `Debug` statements](xref:fundamentals/logging/index#debug), and the output can be viewed from Visual Studio.

To configure the **Debug** logging provider, add a reference in your project to the [`Microsoft.Extensions.Logging.Debug`](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Debug) NuGet package. Next, 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:

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

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

## Additional resources

* [Logging in C# and .NET](/dotnet/core/extensions/logging)
* <xref:fundamentals/logging/index#debug>
2 changes: 2 additions & 0 deletions aspnetcore/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ items:
uid: blazor/hybrid/security/security-considerations
- name: Publish
uid: blazor/hybrid/publish/index
- name: Troubleshoot
uid: blazor/hybrid/troubleshoot
- name: Project structure
uid: blazor/project-structure
- name: Fundamentals
Expand Down