--- title: ASP.NET Core Blazor logging author: guardrex description: Learn about logging in Blazor apps, including log level configuration and how to write log messages from Razor components. monikerRange: '>= aspnetcore-3.1' ms.author: riande ms.custom: mvc ms.date: 12/16/2020 no-loc: [Home, Privacy, Kestrel, appsettings.json, "ASP.NET Core Identity", cookie, Cookie, Blazor, "Blazor Server", "Blazor WebAssembly", "Identity", "Let's Encrypt", Razor, SignalR] uid: blazor/fundamentals/logging zone_pivot_groups: blazor-hosting-models --- # ASP.NET Core Blazor logging ::: zone pivot="webassembly" Configure custom logging in Blazor WebAssembly apps with the property. Add the namespace for to `Program.cs`: ```csharp using Microsoft.AspNetCore.Components.WebAssembly.Hosting; ``` In `Program.Main` of `Program.cs`, set the minimum logging level with and add the custom logging provider: ```csharp var builder = WebAssemblyHostBuilder.CreateDefault(args); ... builder.Logging.SetMinimumLevel(LogLevel.Debug); builder.Logging.AddProvider(new CustomLoggingProvider()); ``` The `Logging` property is of type , so all of the extension methods available on are also available on `Logging`. Logging configuration can be loaded from app settings files. For more information, see . ## SignalR .NET client logging Inject an to add a `WebAssemblyConsoleLogger` to the logging providers passed to . Unlike a traditional , `WebAssemblyConsoleLogger` is a wrapper around browser-specific logging APIs (for example, `console.log`). Use of `WebAssemblyConsoleLogger` makes logging possible within Mono inside a browser context. > [!NOTE] > `WebAssemblyConsoleLogger` is [internal](/dotnet/csharp/language-reference/keywords/internal) and not available for direct use in developer code. Add the namespace for and inject an into the component: ```csharp @using Microsoft.Extensions.Logging @inject ILoggerProvider LoggerProvider ``` In the component's [`OnInitializedAsync` method](xref:blazor/components/lifecycle#component-initialization-oninitializedasync), use : ```csharp var connection = new HubConnectionBuilder() .WithUrl(NavigationManager.ToAbsoluteUri("/chathub")) .ConfigureLogging(logging => logging.AddProvider(LoggerProvider)) .Build(); ``` ::: zone-end ::: zone pivot="server" For general ASP.NET Core logging guidance that pertains to Blazor Server, see . ::: zone-end ## Log in Razor components Loggers respect app startup configuration. The `using` directive for is required to support [IntelliSense](/visualstudio/ide/using-intellisense) completions for APIs, such as and . The following example demonstrates logging with an in components. `Pages/Counter.razor`: ::: moniker range=">= aspnetcore-5.0" [!code-razor[](~/blazor/common/samples/5.x/BlazorSample_WebAssembly/Pages/logging/Counter1.razor?highlight=3,16)] ::: moniker-end ::: moniker range="< aspnetcore-5.0" [!code-razor[](~/blazor/common/samples/3.x/BlazorSample_WebAssembly/Pages/logging/Counter1.razor?highlight=3,16)] ::: moniker-end The following example demonstrates logging with an in components. `Pages/Counter.razor`: ::: moniker range=">= aspnetcore-5.0" [!code-razor[](~/blazor/common/samples/5.x/BlazorSample_WebAssembly/Pages/logging/Counter2.razor?highlight=3,16-17)] ::: moniker-end ::: moniker range="< aspnetcore-5.0" [!code-razor[](~/blazor/common/samples/3.x/BlazorSample_WebAssembly/Pages/logging/Counter2.razor?highlight=3,16-17)] ::: moniker-end ## Additional resources *