Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 14 additions & 2 deletions aspnetcore/blazor/fundamentals/environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,14 @@ For general guidance on ASP.NET Core app configuration, see <xref:fundamentals/e

The following example starts Blazor in the `Staging` environment if the hostname includes `localhost`. Otherwise, the environment is set to its default value.

:::moniker range=">= aspnetcore-8.0"
:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0"

Blazor Web App:

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -148,10 +152,16 @@ Blazor Web App:
> [!NOTE]
> For Blazor Web Apps that set the `webAssembly` > `environment` property in `Blazor.start` configuration, it's wise to match the server-side environment to the environment set on the `environment` property. Otherwise, prerendering on the server operates under a different environment than rendering on the client, which results in arbitrary effects. For general guidance on setting the environment for a Blazor Web App, see <xref:fundamentals/environments>.

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0"

Standalone Blazor WebAssembly:

:::moniker-end

:::moniker range="< aspnetcore-11.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -167,6 +177,8 @@ Standalone Blazor WebAssembly:

**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see <xref:blazor/project-structure#location-of-the-blazor-script>.

:::moniker-end

:::moniker range="< aspnetcore-10.0"

Using the `environment` property overrides the environment set by the [`Blazor-Environment` header](#set-the-client-side-environment-via-header).
Expand All @@ -175,7 +187,7 @@ The preceding approach sets the client's environment without changing the `Blazo

:::moniker-end

To log the environment to the console in either a standalone Blazor WebAssembly app or the `.Client` project of a Blazor Web App, place the following C# code in the `Program` file after the <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHost> is created with <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.CreateDefault%2A?displayProperty=nameWithType> and before the line that builds and runs the project (`await builder.Build().RunAsync();`):
To log the environment to the console in either a standalone Blazor WebAssembly app (all release versions) or the `.Client` project of a Blazor Web App (.NET 8 or later), place the following C# code in the `Program` file after the <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHost> is created with <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.CreateDefault%2A?displayProperty=nameWithType> and before the line that builds and runs the project (`await builder.Build().RunAsync();`):

```csharp
Console.WriteLine(
Expand Down
30 changes: 28 additions & 2 deletions aspnetcore/blazor/fundamentals/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,14 @@ For the `configureLogging` log level value, pass the argument as either the stri

Example 1: Set the <xref:Microsoft.Extensions.Logging.LogLevel.Information> log level with a string value.

:::moniker range=">= aspnetcore-8.0"
:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0"

Blazor Web App:

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -687,10 +691,16 @@ Blazor Web App:
</script>
```

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0"

Blazor Server:

:::moniker-end

:::moniker range="< aspnetcore-11.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -702,14 +712,20 @@ Blazor Server:
</script>
```

:::moniker-end

**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see <xref:blazor/project-structure#location-of-the-blazor-script>.

Example 2: Set the <xref:Microsoft.Extensions.Logging.LogLevel.Information> log level with an integer value.

:::moniker range=">= aspnetcore-8.0"
:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0"

Blazor Web App:

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -723,10 +739,18 @@ Blazor Web App:
</script>
```

**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see <xref:blazor/project-structure#location-of-the-blazor-script>.

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0"

Blazor Server:

:::moniker-end

:::moniker range="< aspnetcore-11.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -740,6 +764,8 @@ Blazor Server:

**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see <xref:blazor/project-structure#location-of-the-blazor-script>.

:::moniker-end

> [!NOTE]
> Using an integer to specify the logging level in Example 2, often referred to as a *magic number* or *magic constant*, is considered a poor coding practice because the integer doesn't clearly identify the logging level when viewing the source code. If minimizing the bytes transferred to the browser is a priority, using an integer might be justified (consider removing the comment in such cases).

Expand Down
Loading
Loading