Soenneker.Serilog.Sinks.Browser.Blazor 3.0.97

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.97
                    
NuGet\Install-Package Soenneker.Serilog.Sinks.Browser.Blazor -Version 3.0.97
                    
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.97" />
                    
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.97" />
                    
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.97
                    
#r "nuget: Soenneker.Serilog.Sinks.Browser.Blazor, 3.0.97"
                    
#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.97
                    
#: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.97
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Serilog.Sinks.Browser.Blazor&version=3.0.97
                    
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
4.0.208 516 11/11/2025
4.0.207 379 11/11/2025
4.0.206 846 11/6/2025
4.0.205 129 11/6/2025
4.0.204 328 11/6/2025
4.0.203 783 11/4/2025
4.0.202 832 10/30/2025
4.0.201 239 10/30/2025
4.0.200 265 10/30/2025
4.0.199 176 10/30/2025
4.0.198 254 10/29/2025
4.0.197 168 10/29/2025
3.0.196 1,445 10/16/2025
3.0.195 569 10/14/2025
3.0.194 4,795 9/21/2025
3.0.193 3,521 9/16/2025
3.0.192 1,978 9/10/2025
3.0.191 364 9/9/2025
3.0.190 417 9/9/2025
3.0.189 319 9/9/2025
3.0.188 1,190 9/3/2025
3.0.187 256 9/3/2025
3.0.186 402 9/3/2025
3.0.185 193 9/3/2025
3.0.184 166 9/3/2025
3.0.183 954 8/16/2025
3.0.182 784 8/11/2025
3.0.181 336 8/11/2025
3.0.180 180 8/11/2025
3.0.179 346 8/11/2025
3.0.178 513 8/11/2025
3.0.177 584 8/5/2025
3.0.176 227 8/5/2025
3.0.175 473 7/29/2025
3.0.174 902 7/8/2025
3.0.173 273 7/8/2025
3.0.172 667 7/3/2025
3.0.171 590 6/28/2025
3.0.170 184 6/27/2025
3.0.169 149 6/27/2025
3.0.168 109 6/27/2025
3.0.167 460 6/24/2025
3.0.166 579 6/11/2025
3.0.165 489 6/10/2025
3.0.164 435 6/10/2025
3.0.163 651 6/2/2025
3.0.162 216 6/2/2025
3.0.161 325 5/27/2025
3.0.160 252 5/27/2025
3.0.159 311 5/27/2025
3.0.158 171 5/27/2025
3.0.157 376 5/25/2025
3.0.156 403 5/23/2025
3.0.155 247 5/23/2025
3.0.154 224 5/22/2025
3.0.153 224 5/22/2025
3.0.152 448 5/18/2025
3.0.151 384 5/14/2025
3.0.150 369 5/13/2025
3.0.149 603 5/8/2025
3.0.148 246 5/8/2025
3.0.147 279 5/8/2025
3.0.146 213 5/8/2025
3.0.145 217 5/7/2025
3.0.144 624 5/5/2025
3.0.143 304 5/5/2025
3.0.142 300 5/5/2025
3.0.141 234 5/5/2025
3.0.140 248 5/5/2025
3.0.139 175 5/5/2025
3.0.138 276 5/5/2025
3.0.137 314 5/5/2025
3.0.136 589 4/27/2025
3.0.135 160 4/26/2025
3.0.134 508 4/9/2025
3.0.133 262 4/9/2025
3.0.132 325 4/8/2025
3.0.131 201 4/8/2025
3.0.130 222 4/8/2025
3.0.129 195 4/8/2025
3.0.128 402 4/8/2025
3.0.127 222 4/8/2025
3.0.126 219 4/8/2025
3.0.125 190 4/8/2025
3.0.124 243 4/8/2025
3.0.123 192 4/8/2025
3.0.122 210 4/8/2025
3.0.121 211 4/7/2025
3.0.120 216 4/7/2025
3.0.119 763 4/7/2025
3.0.118 265 4/7/2025
3.0.117 337 4/7/2025
3.0.116 258 4/7/2025
3.0.115 288 4/7/2025
3.0.114 290 4/7/2025
3.0.113 259 4/7/2025
3.0.112 284 4/6/2025
3.0.111 172 4/6/2025
3.0.110 219 4/6/2025
3.0.109 238 4/6/2025
3.0.108 188 4/6/2025
3.0.107 271 4/6/2025
3.0.106 172 4/6/2025
3.0.105 222 4/6/2025
3.0.104 168 4/6/2025
3.0.103 184 4/6/2025
3.0.102 141 4/6/2025
3.0.101 140 4/6/2025
3.0.100 137 4/6/2025
3.0.99 235 4/6/2025
3.0.98 142 4/6/2025
3.0.97 136 4/6/2025
3.0.96 221 4/5/2025
3.0.95 148 4/5/2025
3.0.94 174 4/5/2025
3.0.93 179 4/5/2025
3.0.92 147 4/5/2025
3.0.91 119 4/5/2025
3.0.90 492 4/4/2025
3.0.89 120 4/4/2025
3.0.88 161 4/4/2025
3.0.87 147 4/4/2025
3.0.86 720 4/3/2025
3.0.85 304 4/1/2025
3.0.84 283 4/1/2025
3.0.83 340 3/31/2025
3.0.82 250 3/31/2025
3.0.81 302 3/31/2025
3.0.80 264 3/29/2025
3.0.79 175 3/29/2025
3.0.78 632 3/25/2025
3.0.77 549 3/25/2025
3.0.76 552 3/25/2025
3.0.75 541 3/24/2025
3.0.74 205 3/21/2025
3.0.73 215 3/21/2025
3.0.72 292 3/18/2025
3.0.71 226 3/18/2025
3.0.70 185 3/15/2025
3.0.69 134 3/15/2025
3.0.68 266 3/12/2025
3.0.67 216 3/12/2025
3.0.66 229 3/12/2025
3.0.65 196 3/12/2025
3.0.64 219 3/12/2025
3.0.63 237 3/11/2025
3.0.62 176 3/11/2025
3.0.61 214 3/11/2025
3.0.60 206 3/11/2025
3.0.59 193 3/11/2025
3.0.58 236 3/11/2025
3.0.57 189 3/11/2025
3.0.56 239 3/11/2025
3.0.55 200 3/11/2025
3.0.54 241 3/11/2025
3.0.53 193 3/11/2025
3.0.52 361 3/7/2025
3.0.51 282 3/7/2025
3.0.50 258 3/2/2025
3.0.49 191 3/2/2025
3.0.48 157 3/2/2025
3.0.47 197 3/2/2025
3.0.46 174 3/1/2025
3.0.45 171 3/1/2025
3.0.44 159 3/1/2025
3.0.43 132 3/1/2025
3.0.42 186 3/1/2025
3.0.41 130 3/1/2025
3.0.40 156 3/1/2025
3.0.39 145 3/1/2025
3.0.38 181 3/1/2025
3.0.37 126 3/1/2025
3.0.36 133 3/1/2025
3.0.35 157 3/1/2025
3.0.34 130 3/1/2025
3.0.33 265 2/25/2025
3.0.32 169 2/25/2025
3.0.31 174 2/25/2025
3.0.30 202 2/25/2025
3.0.29 174 2/25/2025
3.0.28 205 2/24/2025
3.0.27 218 2/23/2025
3.0.26 169 2/23/2025
3.0.25 165 2/22/2025
3.0.24 241 2/22/2025
3.0.23 162 2/22/2025
3.0.22 145 2/22/2025
3.0.21 156 2/22/2025
3.0.20 149 2/22/2025
3.0.19 172 2/21/2025
3.0.18 233 2/21/2025
3.0.17 182 2/21/2025
3.0.16 256 2/19/2025
3.0.15 140 2/19/2025
3.0.14 145 2/19/2025
3.0.13 160 2/18/2025
3.0.12 401 2/18/2025
3.0.11 148 2/18/2025
3.0.10 183 2/18/2025
3.0.9 258 2/14/2025
3.0.8 243 2/13/2025
3.0.7 188 2/12/2025
3.0.6 138 2/12/2025
3.0.5 136 2/12/2025
3.0.4 140 2/12/2025
3.0.3 143 2/12/2025
3.0.2 141 2/12/2025
3.0.1 140 2/12/2025