Soenneker.Serilog.Sinks.Browser.Blazor 3.0.6

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Serilog.Sinks.Browser.Blazor --version 3.0.6
                    
NuGet\Install-Package Soenneker.Serilog.Sinks.Browser.Blazor -Version 3.0.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Serilog.Sinks.Browser.Blazor" Version="3.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Serilog.Sinks.Browser.Blazor" Version="3.0.6" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Serilog.Sinks.Browser.Blazor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Serilog.Sinks.Browser.Blazor --version 3.0.6
                    
#r "nuget: Soenneker.Serilog.Sinks.Browser.Blazor, 3.0.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Serilog.Sinks.Browser.Blazor@3.0.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Serilog.Sinks.Browser.Blazor&version=3.0.6
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Serilog.Sinks.Browser.Blazor&version=3.0.6
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Serilog.Sinks.Browser.Blazor

A Serilog sink for logging within the Blazor client-side environment

image

An example demo app has been added to the solution.

🛠 Installation

  1. Install Required NuGet Packages

    dotnet add package Serilog.Extensions.Logging
    dotnet add package Soenneker.Serilog.Sinks.Browser.Blazor
    
  2. Configure Logging in Program.cs

An example:

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.JSInterop;
using Serilog;
using Serilog.Debugging;
using Serilog.Events;
using Soenneker.Serilog.Sinks.Browser.Blazor.Registrars;

public class Program
{
    public static async Task Main(string[] args)
    {
        try
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);

            ConfigureLogging(builder.Services);

            builder.RootComponents.Add<App>("#app");
            builder.RootComponents.Add<HeadOutlet>("head::after");

            WebAssemblyHost host = builder.Build();

            AddBlazorConsoleLogger(host);

            await host.RunAsync();
        }
        catch (Exception e)
        {
            Log.Error(e, "Stopped program because of exception");
            throw;
        }
        finally
        {
            await Log.CloseAndFlushAsync();
        }
    }

    private static IServiceCollection ConfigureLogging(IServiceCollection services)
    {
        SelfLog.Enable(m => Console.Error.WriteLine(m));

        services.AddLogging(builder =>
        {
            builder.ClearProviders();
            builder.AddSerilog(dispose: true);
        });

        return services;
    }

    private static WebAssemblyHost AddBlazorConsoleLogger(WebAssemblyHost host)
    {
        var jsRuntime = (IJSRuntime)host.Services.GetService(typeof(IJSRuntime))!;

        var loggerConfig = new LoggerConfiguration();

        loggerConfig.WriteTo.BlazorConsole(jsRuntime: jsRuntime);

        Log.Logger = loggerConfig.CreateLogger();

        return host;
    }
}

How It Works

  • ConfigureLogging(IServiceCollection services)
    • Enables Serilog's self-logging to capture any internal errors.
    • Registers Serilog as the primary logging provider.
  • SetGlobalLogger(WebAssemblyHost host)
    • Initializes the BlazorConsole sink to log messages directly in the browser's developer console.

🛠 Usage

Once you have installed and configured Serilog with the BlazorConsole sink, you can start logging messages in your Blazor components.

Injecting the Logger

In your Blazor component (.razor file), inject the ILogger<T> service:

@page "/"
@using Microsoft.Extensions.Logging

@inject ILogger<Index> Logger

<button @onclick="Click">Click</button>

@code {
    public void Click()
    {
        Logger.LogInformation("Testing information log");
    }
}
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.221 369 12/21/2025
4.0.220 1,083 12/15/2025
4.0.219 324 12/15/2025
4.0.218 265 12/15/2025
4.0.217 408 12/12/2025
4.0.216 857 12/10/2025
4.0.215 578 12/9/2025
4.0.214 1,040 11/21/2025
4.0.213 861 11/21/2025
4.0.212 385 11/21/2025
4.0.211 566 11/20/2025
4.0.210 465 11/20/2025
4.0.209 388 11/20/2025
4.0.208 1,366 11/11/2025
4.0.207 457 11/11/2025
4.0.206 858 11/6/2025
4.0.205 141 11/6/2025
4.0.204 343 11/6/2025
4.0.203 800 11/4/2025
4.0.202 844 10/30/2025
4.0.201 252 10/30/2025
4.0.200 279 10/30/2025
4.0.199 192 10/30/2025
4.0.198 270 10/29/2025
4.0.197 182 10/29/2025
3.0.196 1,455 10/16/2025
3.0.195 583 10/14/2025
3.0.194 4,802 9/21/2025
3.0.193 3,525 9/16/2025
3.0.192 1,986 9/10/2025
3.0.191 373 9/9/2025
3.0.190 427 9/9/2025
3.0.189 326 9/9/2025
3.0.188 1,203 9/3/2025
3.0.187 265 9/3/2025
3.0.186 412 9/3/2025
3.0.185 204 9/3/2025
3.0.184 178 9/3/2025
3.0.183 961 8/16/2025
3.0.182 794 8/11/2025
3.0.181 344 8/11/2025
3.0.180 190 8/11/2025
3.0.179 356 8/11/2025
3.0.178 520 8/11/2025
3.0.177 593 8/5/2025
3.0.176 235 8/5/2025
3.0.175 481 7/29/2025
3.0.174 909 7/8/2025
3.0.173 283 7/8/2025
3.0.172 678 7/3/2025
3.0.171 597 6/28/2025
3.0.170 191 6/27/2025
3.0.169 156 6/27/2025
3.0.168 117 6/27/2025
3.0.167 471 6/24/2025
3.0.166 587 6/11/2025
3.0.165 498 6/10/2025
3.0.164 444 6/10/2025
3.0.163 659 6/2/2025
3.0.162 225 6/2/2025
3.0.161 337 5/27/2025
3.0.160 261 5/27/2025
3.0.159 319 5/27/2025
3.0.158 179 5/27/2025
3.0.157 382 5/25/2025
3.0.156 412 5/23/2025
3.0.155 257 5/23/2025
3.0.154 232 5/22/2025
3.0.153 233 5/22/2025
3.0.152 459 5/18/2025
3.0.151 402 5/14/2025
3.0.150 377 5/13/2025
3.0.149 608 5/8/2025
3.0.148 253 5/8/2025
3.0.147 292 5/8/2025
3.0.146 225 5/8/2025
3.0.145 225 5/7/2025
3.0.144 634 5/5/2025
3.0.143 310 5/5/2025
3.0.142 306 5/5/2025
3.0.141 241 5/5/2025
3.0.140 254 5/5/2025
3.0.139 178 5/5/2025
3.0.138 284 5/5/2025
3.0.137 320 5/5/2025
3.0.136 595 4/27/2025
3.0.135 167 4/26/2025
3.0.134 518 4/9/2025
3.0.133 275 4/9/2025
3.0.132 334 4/8/2025
3.0.131 210 4/8/2025
3.0.130 230 4/8/2025
3.0.129 204 4/8/2025
3.0.128 410 4/8/2025
3.0.127 231 4/8/2025
3.0.126 231 4/8/2025
3.0.125 198 4/8/2025
3.0.124 251 4/8/2025
3.0.123 199 4/8/2025
3.0.122 219 4/8/2025
3.0.121 218 4/7/2025
3.0.120 224 4/7/2025
3.0.119 771 4/7/2025
3.0.118 275 4/7/2025
3.0.117 342 4/7/2025
3.0.116 265 4/7/2025
3.0.115 295 4/7/2025
3.0.114 299 4/7/2025
3.0.113 266 4/7/2025
3.0.112 291 4/6/2025
3.0.111 181 4/6/2025
3.0.110 229 4/6/2025
3.0.109 242 4/6/2025
3.0.108 193 4/6/2025
3.0.107 280 4/6/2025
3.0.106 177 4/6/2025
3.0.105 231 4/6/2025
3.0.104 178 4/6/2025
3.0.103 189 4/6/2025
3.0.102 147 4/6/2025
3.0.101 145 4/6/2025
3.0.100 142 4/6/2025
3.0.99 241 4/6/2025
3.0.98 148 4/6/2025
3.0.97 144 4/6/2025
3.0.96 228 4/5/2025
3.0.95 156 4/5/2025
3.0.94 183 4/5/2025
3.0.93 189 4/5/2025
3.0.92 155 4/5/2025
3.0.91 127 4/5/2025
3.0.90 502 4/4/2025
3.0.89 129 4/4/2025
3.0.88 165 4/4/2025
3.0.87 155 4/4/2025
3.0.86 726 4/3/2025
3.0.85 312 4/1/2025
3.0.84 290 4/1/2025
3.0.83 349 3/31/2025
3.0.82 253 3/31/2025
3.0.81 306 3/31/2025
3.0.80 270 3/29/2025
3.0.79 182 3/29/2025
3.0.78 640 3/25/2025
3.0.77 556 3/25/2025
3.0.76 560 3/25/2025
3.0.75 547 3/24/2025
3.0.74 212 3/21/2025
3.0.73 227 3/21/2025
3.0.72 303 3/18/2025
3.0.71 230 3/18/2025
3.0.70 191 3/15/2025
3.0.69 143 3/15/2025
3.0.68 279 3/12/2025
3.0.67 222 3/12/2025
3.0.66 242 3/12/2025
3.0.65 204 3/12/2025
3.0.64 227 3/12/2025
3.0.63 247 3/11/2025
3.0.62 182 3/11/2025
3.0.61 221 3/11/2025
3.0.60 220 3/11/2025
3.0.59 201 3/11/2025
3.0.58 245 3/11/2025
3.0.57 196 3/11/2025
3.0.56 245 3/11/2025
3.0.55 206 3/11/2025
3.0.54 245 3/11/2025
3.0.53 200 3/11/2025
3.0.52 369 3/7/2025
3.0.51 291 3/7/2025
3.0.50 268 3/2/2025
3.0.49 201 3/2/2025
3.0.48 162 3/2/2025
3.0.47 203 3/2/2025
3.0.46 181 3/1/2025
3.0.45 181 3/1/2025
3.0.44 165 3/1/2025
3.0.43 137 3/1/2025
3.0.42 194 3/1/2025
3.0.41 139 3/1/2025
3.0.40 166 3/1/2025
3.0.39 151 3/1/2025
3.0.38 190 3/1/2025
3.0.37 132 3/1/2025
3.0.36 143 3/1/2025
3.0.35 164 3/1/2025
3.0.34 136 3/1/2025
3.0.33 270 2/25/2025
3.0.32 177 2/25/2025
3.0.31 182 2/25/2025
3.0.30 211 2/25/2025
3.0.29 181 2/25/2025
3.0.28 212 2/24/2025
3.0.27 225 2/23/2025
3.0.26 175 2/23/2025
3.0.25 172 2/22/2025
3.0.24 248 2/22/2025
3.0.23 168 2/22/2025
3.0.22 153 2/22/2025
3.0.21 164 2/22/2025
3.0.20 156 2/22/2025
3.0.19 181 2/21/2025
3.0.18 243 2/21/2025
3.0.17 187 2/21/2025
3.0.16 267 2/19/2025
3.0.15 151 2/19/2025
3.0.14 154 2/19/2025
3.0.13 170 2/18/2025
3.0.12 410 2/18/2025
3.0.11 154 2/18/2025
3.0.10 189 2/18/2025
3.0.9 266 2/14/2025
3.0.8 252 2/13/2025
3.0.7 194 2/12/2025
3.0.6 144 2/12/2025
3.0.5 142 2/12/2025
3.0.4 147 2/12/2025
3.0.3 151 2/12/2025
3.0.2 150 2/12/2025
3.0.1 148 2/12/2025