Soenneker.Serilog.Sinks.Browser.Blazor 3.0.188

Prefix Reserved
dotnet add package Soenneker.Serilog.Sinks.Browser.Blazor --version 3.0.188
                    
NuGet\Install-Package Soenneker.Serilog.Sinks.Browser.Blazor -Version 3.0.188
                    
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.188" />
                    
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.188" />
                    
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.188
                    
#r "nuget: Soenneker.Serilog.Sinks.Browser.Blazor, 3.0.188"
                    
#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.188
                    
#: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.188
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Serilog.Sinks.Browser.Blazor&version=3.0.188
                    
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 Soenneker.Serilog.Sinks.Browser.Blazor
  1. 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 = host.Services.GetRequiredService<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
3.0.188 132 9/3/2025
3.0.187 106 9/3/2025
3.0.186 253 9/3/2025
3.0.185 45 9/3/2025
3.0.184 29 9/3/2025
3.0.183 865 8/16/2025
3.0.182 740 8/11/2025
3.0.181 308 8/11/2025
3.0.180 140 8/11/2025
3.0.179 306 8/11/2025
3.0.178 469 8/11/2025
3.0.177 543 8/5/2025
3.0.176 196 8/5/2025
3.0.175 443 7/29/2025
3.0.174 589 7/8/2025
3.0.173 245 7/8/2025
3.0.172 649 7/3/2025
3.0.171 558 6/28/2025
3.0.170 167 6/27/2025
3.0.169 119 6/27/2025
3.0.168 80 6/27/2025
3.0.167 428 6/24/2025
3.0.166 537 6/11/2025
3.0.165 461 6/10/2025
3.0.164 406 6/10/2025
3.0.163 620 6/2/2025
3.0.162 188 6/2/2025
3.0.161 298 5/27/2025
3.0.160 224 5/27/2025
3.0.159 283 5/27/2025
3.0.158 141 5/27/2025
3.0.157 345 5/25/2025
3.0.156 376 5/23/2025
3.0.155 218 5/23/2025
3.0.154 193 5/22/2025
3.0.153 196 5/22/2025
3.0.152 421 5/18/2025
3.0.151 354 5/14/2025
3.0.150 342 5/13/2025
3.0.149 573 5/8/2025
3.0.148 217 5/8/2025
3.0.147 249 5/8/2025
3.0.146 185 5/8/2025
3.0.145 186 5/7/2025
3.0.144 596 5/5/2025
3.0.143 277 5/5/2025
3.0.142 272 5/5/2025
3.0.141 205 5/5/2025
3.0.140 220 5/5/2025
3.0.139 156 5/5/2025
3.0.138 249 5/5/2025
3.0.137 286 5/5/2025
3.0.136 560 4/27/2025
3.0.135 132 4/26/2025
3.0.134 490 4/9/2025
3.0.133 235 4/9/2025
3.0.132 297 4/8/2025
3.0.131 174 4/8/2025
3.0.130 184 4/8/2025
3.0.129 168 4/8/2025
3.0.128 373 4/8/2025
3.0.127 195 4/8/2025
3.0.126 190 4/8/2025
3.0.125 164 4/8/2025
3.0.124 215 4/8/2025
3.0.123 164 4/8/2025
3.0.122 193 4/8/2025
3.0.121 190 4/7/2025
3.0.120 188 4/7/2025
3.0.119 745 4/7/2025
3.0.118 238 4/7/2025
3.0.117 307 4/7/2025
3.0.116 229 4/7/2025
3.0.115 261 4/7/2025
3.0.114 254 4/7/2025
3.0.113 228 4/7/2025
3.0.112 255 4/6/2025
3.0.111 152 4/6/2025
3.0.110 191 4/6/2025
3.0.109 208 4/6/2025
3.0.108 159 4/6/2025
3.0.107 234 4/6/2025
3.0.106 141 4/6/2025
3.0.105 192 4/6/2025
3.0.104 139 4/6/2025
3.0.103 157 4/6/2025
3.0.102 113 4/6/2025
3.0.101 111 4/6/2025
3.0.100 109 4/6/2025
3.0.99 206 4/6/2025
3.0.98 114 4/6/2025
3.0.97 107 4/6/2025
3.0.96 190 4/5/2025
3.0.95 121 4/5/2025
3.0.94 146 4/5/2025
3.0.93 150 4/5/2025
3.0.92 117 4/5/2025
3.0.91 89 4/5/2025
3.0.90 464 4/4/2025
3.0.89 91 4/4/2025
3.0.88 132 4/4/2025
3.0.87 119 4/4/2025
3.0.86 701 4/3/2025
3.0.85 274 4/1/2025
3.0.84 254 4/1/2025
3.0.83 311 3/31/2025
3.0.82 220 3/31/2025
3.0.81 273 3/31/2025
3.0.80 230 3/29/2025
3.0.79 144 3/29/2025
3.0.78 603 3/25/2025
3.0.77 509 3/25/2025
3.0.76 522 3/25/2025
3.0.75 509 3/24/2025
3.0.74 177 3/21/2025
3.0.73 182 3/21/2025
3.0.72 261 3/18/2025
3.0.71 196 3/18/2025
3.0.70 158 3/15/2025
3.0.69 104 3/15/2025
3.0.68 239 3/12/2025
3.0.67 188 3/12/2025
3.0.66 202 3/12/2025
3.0.65 168 3/12/2025
3.0.64 190 3/12/2025
3.0.63 207 3/11/2025
3.0.62 158 3/11/2025
3.0.61 184 3/11/2025
3.0.60 179 3/11/2025
3.0.59 163 3/11/2025
3.0.58 205 3/11/2025
3.0.57 161 3/11/2025
3.0.56 210 3/11/2025
3.0.55 172 3/11/2025
3.0.54 223 3/11/2025
3.0.53 163 3/11/2025
3.0.52 333 3/7/2025
3.0.51 251 3/7/2025
3.0.50 240 3/2/2025
3.0.49 154 3/2/2025
3.0.48 131 3/2/2025
3.0.47 167 3/2/2025
3.0.46 147 3/1/2025
3.0.45 143 3/1/2025
3.0.44 130 3/1/2025
3.0.43 105 3/1/2025
3.0.42 158 3/1/2025
3.0.41 103 3/1/2025
3.0.40 137 3/1/2025
3.0.39 118 3/1/2025
3.0.38 153 3/1/2025
3.0.37 107 3/1/2025
3.0.36 105 3/1/2025
3.0.35 130 3/1/2025
3.0.34 102 3/1/2025
3.0.33 238 2/25/2025
3.0.32 143 2/25/2025
3.0.31 142 2/25/2025
3.0.30 175 2/25/2025
3.0.29 142 2/25/2025
3.0.28 175 2/24/2025
3.0.27 190 2/23/2025
3.0.26 140 2/23/2025
3.0.25 139 2/22/2025
3.0.24 210 2/22/2025
3.0.23 136 2/22/2025
3.0.22 118 2/22/2025
3.0.21 127 2/22/2025
3.0.20 119 2/22/2025
3.0.19 145 2/21/2025
3.0.18 203 2/21/2025
3.0.17 153 2/21/2025
3.0.16 228 2/19/2025
3.0.15 113 2/19/2025
3.0.14 118 2/19/2025
3.0.13 129 2/18/2025
3.0.12 373 2/18/2025
3.0.11 119 2/18/2025
3.0.10 156 2/18/2025
3.0.9 232 2/14/2025
3.0.8 216 2/13/2025
3.0.7 162 2/12/2025
3.0.6 111 2/12/2025
3.0.5 119 2/12/2025
3.0.4 111 2/12/2025
3.0.3 115 2/12/2025
3.0.2 114 2/12/2025
3.0.1 109 2/12/2025