Soenneker.Serilog.Sinks.Browser.Blazor 3.0.3

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.3
                    
NuGet\Install-Package Soenneker.Serilog.Sinks.Browser.Blazor -Version 3.0.3
                    
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.3" />
                    
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.3" />
                    
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.3
                    
#r "nuget: Soenneker.Serilog.Sinks.Browser.Blazor, 3.0.3"
                    
#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.3
                    
#: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.3
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Serilog.Sinks.Browser.Blazor&version=3.0.3
                    
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();

            SetGlobalLogger(host);

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

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

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

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

        var loggerConfig = new LoggerConfiguration();

        loggerConfig.WriteTo.BlazorConsole(jsRuntime: jsRuntime);

        Log.Logger = loggerConfig.CreateLogger();
    }
}

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.194 3,583 9/21/2025
3.0.193 3,510 9/16/2025
3.0.192 1,959 9/10/2025
3.0.191 344 9/9/2025
3.0.190 398 9/9/2025
3.0.189 295 9/9/2025
3.0.188 1,170 9/3/2025
3.0.187 239 9/3/2025
3.0.186 370 9/3/2025
3.0.185 176 9/3/2025
3.0.184 149 9/3/2025
3.0.183 935 8/16/2025
3.0.182 763 8/11/2025
3.0.181 320 8/11/2025
3.0.180 153 8/11/2025
3.0.179 328 8/11/2025
3.0.178 491 8/11/2025
3.0.177 555 8/5/2025
3.0.176 198 8/5/2025
3.0.175 455 7/29/2025
3.0.174 851 7/8/2025
3.0.173 267 7/8/2025
3.0.172 661 7/3/2025
3.0.171 581 6/28/2025
3.0.170 179 6/27/2025
3.0.169 142 6/27/2025
3.0.168 103 6/27/2025
3.0.167 433 6/24/2025
3.0.166 568 6/11/2025
3.0.165 483 6/10/2025
3.0.164 429 6/10/2025
3.0.163 643 6/2/2025
3.0.162 210 6/2/2025
3.0.161 320 5/27/2025
3.0.160 237 5/27/2025
3.0.159 305 5/27/2025
3.0.158 153 5/27/2025
3.0.157 357 5/25/2025
3.0.156 398 5/23/2025
3.0.155 240 5/23/2025
3.0.154 205 5/22/2025
3.0.153 208 5/22/2025
3.0.152 433 5/18/2025
3.0.151 376 5/14/2025
3.0.150 364 5/13/2025
3.0.149 595 5/8/2025
3.0.148 239 5/8/2025
3.0.147 271 5/8/2025
3.0.146 207 5/8/2025
3.0.145 209 5/7/2025
3.0.144 618 5/5/2025
3.0.143 289 5/5/2025
3.0.142 294 5/5/2025
3.0.141 217 5/5/2025
3.0.140 242 5/5/2025
3.0.139 169 5/5/2025
3.0.138 270 5/5/2025
3.0.137 309 5/5/2025
3.0.136 582 4/27/2025
3.0.135 154 4/26/2025
3.0.134 502 4/9/2025
3.0.133 257 4/9/2025
3.0.132 319 4/8/2025
3.0.131 196 4/8/2025
3.0.130 216 4/8/2025
3.0.129 190 4/8/2025
3.0.128 395 4/8/2025
3.0.127 217 4/8/2025
3.0.126 212 4/8/2025
3.0.125 186 4/8/2025
3.0.124 237 4/8/2025
3.0.123 176 4/8/2025
3.0.122 205 4/8/2025
3.0.121 202 4/7/2025
3.0.120 210 4/7/2025
3.0.119 757 4/7/2025
3.0.118 260 4/7/2025
3.0.117 330 4/7/2025
3.0.116 251 4/7/2025
3.0.115 284 4/7/2025
3.0.114 286 4/7/2025
3.0.113 253 4/7/2025
3.0.112 278 4/6/2025
3.0.111 164 4/6/2025
3.0.110 214 4/6/2025
3.0.109 230 4/6/2025
3.0.108 171 4/6/2025
3.0.107 257 4/6/2025
3.0.106 163 4/6/2025
3.0.105 216 4/6/2025
3.0.104 162 4/6/2025
3.0.103 179 4/6/2025
3.0.102 136 4/6/2025
3.0.101 133 4/6/2025
3.0.100 121 4/6/2025
3.0.99 228 4/6/2025
3.0.98 136 4/6/2025
3.0.97 131 4/6/2025
3.0.96 212 4/5/2025
3.0.95 133 4/5/2025
3.0.94 168 4/5/2025
3.0.93 172 4/5/2025
3.0.92 140 4/5/2025
3.0.91 101 4/5/2025
3.0.90 486 4/4/2025
3.0.89 113 4/4/2025
3.0.88 154 4/4/2025
3.0.87 142 4/4/2025
3.0.86 713 4/3/2025
3.0.85 296 4/1/2025
3.0.84 276 4/1/2025
3.0.83 333 3/31/2025
3.0.82 244 3/31/2025
3.0.81 295 3/31/2025
3.0.80 253 3/29/2025
3.0.79 166 3/29/2025
3.0.78 625 3/25/2025
3.0.77 544 3/25/2025
3.0.76 544 3/25/2025
3.0.75 533 3/24/2025
3.0.74 199 3/21/2025
3.0.73 205 3/21/2025
3.0.72 285 3/18/2025
3.0.71 218 3/18/2025
3.0.70 180 3/15/2025
3.0.69 126 3/15/2025
3.0.68 261 3/12/2025
3.0.67 211 3/12/2025
3.0.66 224 3/12/2025
3.0.65 190 3/12/2025
3.0.64 213 3/12/2025
3.0.63 230 3/11/2025
3.0.62 171 3/11/2025
3.0.61 208 3/11/2025
3.0.60 202 3/11/2025
3.0.59 186 3/11/2025
3.0.58 229 3/11/2025
3.0.57 184 3/11/2025
3.0.56 233 3/11/2025
3.0.55 194 3/11/2025
3.0.54 235 3/11/2025
3.0.53 185 3/11/2025
3.0.52 354 3/7/2025
3.0.51 274 3/7/2025
3.0.50 252 3/2/2025
3.0.49 186 3/2/2025
3.0.48 142 3/2/2025
3.0.47 188 3/2/2025
3.0.46 168 3/1/2025
3.0.45 165 3/1/2025
3.0.44 141 3/1/2025
3.0.43 126 3/1/2025
3.0.42 180 3/1/2025
3.0.41 124 3/1/2025
3.0.40 148 3/1/2025
3.0.39 139 3/1/2025
3.0.38 174 3/1/2025
3.0.37 119 3/1/2025
3.0.36 126 3/1/2025
3.0.35 152 3/1/2025
3.0.34 123 3/1/2025
3.0.33 259 2/25/2025
3.0.32 164 2/25/2025
3.0.31 163 2/25/2025
3.0.30 196 2/25/2025
3.0.29 165 2/25/2025
3.0.28 197 2/24/2025
3.0.27 211 2/23/2025
3.0.26 162 2/23/2025
3.0.25 160 2/22/2025
3.0.24 231 2/22/2025
3.0.23 157 2/22/2025
3.0.22 139 2/22/2025
3.0.21 148 2/22/2025
3.0.20 130 2/22/2025
3.0.19 167 2/21/2025
3.0.18 224 2/21/2025
3.0.17 164 2/21/2025
3.0.16 251 2/19/2025
3.0.15 134 2/19/2025
3.0.14 139 2/19/2025
3.0.13 150 2/18/2025
3.0.12 394 2/18/2025
3.0.11 140 2/18/2025
3.0.10 177 2/18/2025
3.0.9 253 2/14/2025
3.0.8 238 2/13/2025
3.0.7 173 2/12/2025
3.0.6 122 2/12/2025
3.0.5 131 2/12/2025
3.0.4 134 2/12/2025
3.0.3 137 2/12/2025
3.0.2 135 2/12/2025
3.0.1 132 2/12/2025