Set Up Logs for Blazor WebAssembly

Structured logs allow you to send, view and query logs sent from your applications within Sentry using the .NET SDK.

Set up with Sentry CLI
curl https://cli.sentry.dev/install -fsS | bash

With Sentry Structured Logs, you can send text-based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.

Logs for Blazor WebAssembly are supported in Sentry Blazor WebAssembly SDK version 5.14.0 and above.

Logs sent through the SentrySdk.Logger APIs are always sent, so they don't need any extra configuration.

To also send the entries your app writes through ILogger, set EnableLogs to true:

.UseSentry(options =>
{
    options.Dsn = "___PUBLIC_DSN___";
    // Send ILogger entries to Sentry as logs
    options.EnableLogs = true;
});

If your app also sends ILogger entries through Serilog, NLog, or log4net, leave EnableLogs off and set up the framework as shown below, so each entry reaches Sentry once.

Serilog

In an app that calls UseSentry, add Serilog to the builder's services with AddSerilog from the Serilog.Extensions.Hosting package, and add the sink there:

Program.cs
using Sentry.Serilog;
using Serilog;

builder.Services.AddSerilog(config => config.WriteTo.Sentry());
builder.UseSentry(options =>
{
    options.Dsn = "___PUBLIC_DSN___";
    options.UseSerilog();
});

AddSerilog replaces the app's ILogger factory with Serilog's, so each ILogger entry reaches Sentry once, through the sink. Don't use builder.Logging.AddSerilog() or writeToProviders: true instead. Both also send each entry through the ILogger integration that UseSentry adds, so Sentry receives it twice.

NLog

In an app that calls UseSentry, add NLog with AddNLog from the NLog.Extensions.Logging package, and set ReplaceLoggerFactory:

Program.cs
using NLog;
using NLog.Config;
using NLog.Extensions.Logging;

var config = new LoggingConfiguration();
config.AddSentry();
LogManager.Configuration = config;

builder.Logging.AddNLog(new NLogProviderOptions { ReplaceLoggerFactory = true });
builder.UseSentry(options =>
{
    options.Dsn = "___PUBLIC_DSN___";
});

ReplaceLoggerFactory replaces the app's ILogger factory with NLog's, so each ILogger entry reaches Sentry once, through the target. Without it, NLog runs alongside the ILogger integration that UseSentry adds, and Sentry receives every entry twice. NLog's rules then decide which entries are logged, instead of the Logging section of your configuration. The target sends entries at Info or higher to Sentry as logs. To change that level, set MinimumLogLevel. In ASP.NET Core, UseNLog from the NLog.Web.AspNetCore package takes the same option.

log4net

If an app that calls UseSentry also sends ILogger entries to log4net, for example with AddLog4Net() from the Microsoft.Extensions.Logging.Log4Net.AspNetCore package, both the appender and the ILogger integration that UseSentry adds capture each entry. Turn off events and breadcrumbs from the ILogger integration and leave EnableLogs off, so each entry reaches Sentry once, through the appender:

Program.cs
builder.UseSentry(options =>
{
    options.Dsn = "___PUBLIC_DSN___";
    options.MinimumBreadcrumbLevel = LogLevel.None;
    options.MinimumEventLevel = LogLevel.None;
});

It does not capture the Console.WriteLine() standard output stream.

Once the feature is enabled and the SDK is initialized, you can send logs using instances of the ILogger interface, resolved through .NET dependency injection.

Sentry respects your existing Microsoft.Extensions.Logging provider/category configuration.

The LoggerExtensions extension methods expose various overloads that you can use to log messages at six different log levels automatically mapped to Sentry's severity:

Microsoft.Extensions.Logging.LogLevelSentry.SentryLogLevelSentry Logs UI Severity
TraceTracetrace
DebugDebugdebug
InformationInfoinfo
WarningWarningwarn
ErrorErrorerror
CriticalFatalfatal

These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column.

public sealed class MyService(ILogger<MyService> logger)
{
    public void Invoke()
    {
        logger.LogInformation("A simple log message");
        logger.LogError("A {Parameter} log message", "formatted");
        logger.LogWarning(new EventId(1, nameof(Invoke)), "Message with EventId");
    }
}

The ILogger's CategoryName, as well as the EventId (if provided), are attached as attributes to the logs.

For more information, see the article on Logging in C# and .NET. Sentry Structured Logs also work with High-performance logging in .NET and Compile-time logging source generation alike.

Set to true to send the entries your app writes through the ILogger<TCategoryName> API to Sentry as logs. Defaults to false.

This option doesn't apply to logs sent through the SentrySdk.Logger APIs or through the Serilog, NLog, and log4net integrations. Those logs are always sent.

Changed in Version 7.0.0

In earlier versions, EnableLogs was an option on SentryOptions, and the Serilog, NLog, and log4net integrations only sent logs when it was true.

Sentry's Microsoft.Extensions.Logging provider defines the alias Sentry.

Logs emitted through ILogger<T> are sent to Sentry according to your configured provider/category filters and log levels.

Use standard Microsoft.Extensions.Logging filtering to reduce noisy categories or disable the Sentry provider:

appsettings.json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    },
    "Sentry": {
      "LogLevel": {
        "Default": "None"
      }
    }
  }
}

Setting Logging:Sentry:LogLevel:Default to None disables logs sent through the Microsoft.Extensions.Logging provider for all categories. Logs sent through the SentrySdk.Logger APIs aren't affected by these filters and are still sent.

Example with Logging:Sentry:LogLevel:Default = None:

logger.LogInformation("Will not be sent to Sentry through Microsoft.Extensions.Logging");
SentrySdk.Logger.LogInfo("Still sent via SentrySdk.Logger");

You can also configure filters in code:

// Default minimum level for all categories
builder.Logging.AddFilter(null, LogLevel.Warning);
// Override for a specific category
builder.Logging.AddFilter("MyApp.Namespace", LogLevel.Information);

For background on provider/category filtering, see Logging in C# and .NET.

To filter logs or update them before they are sent to Sentry, you can use the SetBeforeSendLog(Func<SentryLog, SentryLog?>) option.

options =>
{
    options.Dsn = "___PUBLIC_DSN___";
    // a callback that is invoked before sending a log to Sentry
    options.SetBeforeSendLog(static log =>
    {
        // filter out all info logs
        if (log.Level is SentryLogLevel.Info)
        {
            return null;
        }

        // filter out logs based on some attribute they have
        if (log.TryGetAttribute("suppress", out var attribute) && attribute is true)
        {
            return null;
        }

        // set a custom attribute for all other logs sent to Sentry
        log.SetAttribute("my.attribute", "value");

        return log;
    });
});

The beforeSendLog delegate receives a log object, and should return the log object if you want it to be sent to Sentry, or null if you want to discard it.

The log object of type SentryLog has the following members:

MemberTypeDescription
TimestampDateTimeOffsetThe timestamp of the log.
TraceIdSentryIdThe trace id of the log.
LevelSentryLogLevelThe severity level of the log. Either Trace, Debug, Info, Warning, Error, or Fatal.
MessagestringThe formatted log message.
Templatestring?The parameterized template string.
ParametersImmutableArray<KeyValuePair<string, object>>The parameters to the template string.
SpanIdSpanId?The span id of the span that was active when the log was collected.
TryGetAttribute(string key, out object value)MethodGets the attribute value associated with the specified key. Returns true if the log contains an attribute with the specified key and it's value is not null, otherwise false.
SetAttribute(string key, object value)MethodSets a key-value pair of data attached to the log. Supported types are string, bool, integers up to a size of 64-bit signed, and floating-point numbers up to a size of 64-bit.

Instead of many thin logs that are hard to correlate, emit one comprehensive log per operation with all relevant context.

This makes debugging dramatically faster — one query returns everything about a specific order, user, or request.

// ❌ Scattered thin logs
SentrySdk.Logger.LogInfo("Starting checkout");
SentrySdk.Logger.LogInfo("Validating cart");
SentrySdk.Logger.LogInfo("Processing payment");
SentrySdk.Logger.LogInfo("Checkout complete");

// ✅ One wide event with full context
SentrySdk.Logger.LogInfo(log =>
{
    log.SetAttribute("order_id", order.Id);
    log.SetAttribute("user_id", user.Id);
    log.SetAttribute("user_tier", user.Subscription);
    log.SetAttribute("cart_value", cart.Total);
    log.SetAttribute("item_count", cart.Items.Count);
    log.SetAttribute("payment_method", "stripe");
    log.SetAttribute("duration_ms", stopwatch.ElapsedMilliseconds);
}, "Checkout completed");

Add attributes that help you prioritize and debug:

  • User context — tier, account age, lifetime value
  • Transaction data — order value, item count
  • Feature state — active feature flags
  • Request metadata — endpoint, method, duration

This lets you filter logs by high-value customers or specific features.

SentrySdk.Logger.LogInfo(log =>
{
    // User context
    log.SetAttribute("user_id", user.Id);
    log.SetAttribute("user_tier", user.Plan); // "free" | "pro" | "enterprise"
    log.SetAttribute("account_age_days", user.AgeDays);

    // Request data
    log.SetAttribute("endpoint", "/api/orders");
    log.SetAttribute("method", "POST");
    log.SetAttribute("duration_ms", 234);

    // Business context
    log.SetAttribute("order_value", 149.99);
}, "API request completed");

Pick a naming convention and stick with it across your codebase. Inconsistent names make queries impossible.

Recommended: Use snake_case for custom attributes to match common conventions.

// ❌ Inconsistent naming
log.SetAttribute("user", "123");
log.SetAttribute("userId", "123");
log.SetAttribute("user_id", "123");
log.SetAttribute("UserID", "123");

// ✅ Consistent snake_case
SentrySdk.Logger.LogInfo(log =>
{
    log.SetAttribute("user_id", "123");
    log.SetAttribute("order_id", "456");
    log.SetAttribute("cart_value", 99.99);
    log.SetAttribute("item_count", 3);
}, "Order processed");

The .NET SDK automatically sets several default attributes on all log entries to provide context and improve debugging:

  • environment: The environment set in the SDK if defined. This is sent from the SDK as sentry.environment.
  • release: The release set in the SDK if defined. This is sent from the SDK as sentry.release.
  • sdk.name: The name of the SDK that sent the log. This is sent from the SDK as sentry.sdk.name.
  • sdk.version: The version of the SDK that sent the log. This is sent from the SDK as sentry.sdk.version.

If the log was parameterized, Sentry adds the message template and parameters as log attributes.

  • message.template: The parameterized template string. This is sent from the SDK as sentry.message.template.
  • message.parameter.X: The parameters to fill the template string. X can either be the number that represent the parameter's position in the template string (sentry.message.parameter.0, sentry.message.parameter.1, etc) or the parameter's name (sentry.message.parameter.item_id, sentry.message.parameter.user_id, etc). This is sent from the SDK as sentry.message.parameter.X.

  • server.address: The address of the server that sent the log. Equivalent to server_name that gets attached to Sentry errors.

If user information is available in the current scope, the following attributes are added to the log:

  • user.id: The user ID.
  • user.name: The username.
  • user.email: The email address.

If a log is generated by an SDK integration, the SDK will set additional attributes to help you identify the source of the log.

  • origin: The origin of the log. This is sent from the SDK as sentry.origin.

Available integrations:

If there's an integration you would like to see, open a new issue on GitHub.

Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").