@guardrex when #17820 merges, you'll probably need to apply these
But I'd like them towards the end of the file, so you'll have to add something like:
For Blazor WebAssembly, see [Create logs in Blazor WebAssembly](#clbw) in this doc.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Isn't it just going to 💥 merge conflict 💥 when the logging PR goes off of draft and then be resolved there (🤞 in the GH editor we hope 🤞) ?
No need for the anchor-thingy ... the Blazor topics link to headings. I put the content below :point_down:, so it's an easy cut-'n-paste.
### Create logs in Blazor WebAssembly
Configure logging in Blazor WebAssembly apps with the `WebAssemblyHostBuilder.Logging` property in `Program.Main`:
------------- CODEcsharp
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
...
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Logging.SetMinimumLevel(LogLevel.Debug);
builder.Logging.AddProvider(new CustomLoggingProvider());
------------- CODE
The `Logging` property is of type <xref:Microsoft.Extensions.Logging.ILoggingBuilder>, so all of the extension methods available on <xref:Microsoft.Extensions.Logging.ILoggingBuilder> are also available on `Logging`.
... and ...
### Create logs in Blazor
#### Blazor WebAssembly
------------- EXISTING TEXT START -------------
Configure logging in Blazor WebAssembly apps with the `WebAssemblyHostBuilder.Logging` property in `Program.Main`:
------------- CODEcsharp
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
...
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Logging.SetMinimumLevel(LogLevel.Debug);
builder.Logging.AddProvider(new CustomLoggingProvider());
------------- CODE
The `Logging` property is of type <xref:Microsoft.Extensions.Logging.ILoggingBuilder>, so all of the extension methods available on <xref:Microsoft.Extensions.Logging.ILoggingBuilder> are also available on `Logging`.
------------- EXISTING TEXT END -------------
#### Log in Razor components
Loggers respect app startup configuration in the Razor components of Blazor WebAssembly and Blazor Server apps.
The `using` directive for <xref:Microsoft.Extensions.Logging> is required to support Intellisense completions for APIs, such as <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogWarning%2A> and <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogError%2A>.
The following example demonstrates logging with an <xref:Microsoft.Extensions.Logging.ILogger> in Razor components:
------------- CODErazor
@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.LogWarning("Someone has clicked me!");
currentCount++;
}
}
------------- CODE
The following example demonstrates logging with an <xref:Microsoft.Extensions.Logging.ILoggerFactory> in Razor components:
------------- CODErazor
@page "/counter"
@using Microsoft.Extensions.Logging;
@inject ILoggerFactory LoggerFactory
<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()
{
var logger = LoggerFactory.CreateLogger<Counter>();
logger.LogWarning("Someone has clicked me!");
currentCount++;
}
}
------------- CODE
@guardrex the only merge conflict was the date. GitHub did a mircale merge itself.
All that content made it.
WOOT! 😀
Most helpful comment
All that content made it.