Bugwatchbugwatch

SDK · .NET

.NET / C#

Official Bugwatch SDK for .NET 8+. Zero external dependencies. Events are sent on background tasks, so a slow or down Bugwatch server never stalls your application. Stack traces capture file, method and line for every frame.

Install

Shell
dotnet add package Bugwatch.Sdk

Or reference the built DLL directly: Bugwatch.Sdk.dll (targets net8.0).

Quickstart

C#
using Bugwatch;

// Global client
Bugwatch.Init("https://bw-YOUR_KEY@bugwatch-api.loadmindx.com/api/1", new BugwatchOptions
{
    Environment = "production",
    Release = "1.0.0",
});

Bugwatch.CaptureMessage("Payment confirmed", Level.Info);

try
{
    throw new InvalidOperationException("boom");
}
catch (Exception ex)
{
    Bugwatch.CaptureException(ex);  // full stack trace
}

// IMPORTANT: wait for async sends before process exit
Bugwatch.Flush();

Dependency injection

C#
using var client = new BugwatchClient(dsn, new BugwatchOptions
{
    AllowHttp = false,
});

client.SetTag("region", "eu-west");
client.SetUser("42", new Dictionary<string, object?> { ["plan"] = "pro" });
client.AddBreadcrumb(new Breadcrumb { Category = "db", Message = "query users" });

client.CaptureException(ex);
client.Flush();

Prefer an explicit BugwatchClient instance for DI containers — it implements IDisposable and exposes the same capture API as the static class.

API

APIDescription
Init(dsn, options) / new BugwatchClient(dsn, options)Parse the DSN, validate HTTPS (unless AllowHttp), prepare the HttpClient.
CaptureMessage(msg, level) -> string?Capture a message: debug, info, warning, error or fatal. Returns the event id.
CaptureException(ex, level) -> string?Capture an exception with full stack trace (file, method, line).
SetTag(k, v)Set a tag on subsequent events.
SetUser(id, extra)Set user context (PII stripped).
AddBreadcrumb(Breadcrumb)Append to the breadcrumb trail (max 100).
ClearScope()Clear tags, user, context and breadcrumbs.
Flush()Wait for pending async sends. Call it before the process exits.
Dispose()Release the HttpClient (client instance only).

Options

APIDescription
EnvironmentEnvironment name sent with every event.
ReleaseRelease/version identifier.
SampleRate0.0–1.0 fraction of events to keep.
DebugLog send failures to stderr.
AllowHttpSet true to allow plain HTTP DSNs (tests only).