### Nancy Bootstrapper Options Source: https://context7.com/getsentry/raven-csharp/llms.txt Examples of configuring Nancy integration with SharpRaven. Option A uses app.config automatically. Option B registers the DSN programmatically. Option C shows manual event capture. ```csharp using Nancy; using Nancy.TinyIoc; using SharpRaven; // Option A: DSN from app.config (automatic – nothing extra needed) public class Bootstrapper : DefaultNancyBootstrapper { } // Option B: Register DSN programmatically public class Bootstrapper : DefaultNancyBootstrapper { protected override void ApplicationStartup(TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines) { base.ApplicationStartup(container, pipelines); container.Register(new Dsn("https://public_key@sentry.io/project-id")); } } // Option C: Inject IRavenClient in any Nancy module to capture events manually public class OrderModule : NancyModule { private readonly IRavenClient _raven; public OrderModule(IRavenClient raven) { _raven = raven; Get["/order/{id}"] = _ => { try { return GetOrder(_.id); } catch (Exception ex) { _raven.Capture(new SentryEvent(ex)); return HttpStatusCode.InternalServerError; } }; } } ``` -------------------------------- ### Instantiate RavenClient with DSN Source: https://github.com/getsentry/raven-csharp/blob/develop/README.md Initialize the Sentry client by providing your Data Source Name (DSN). This is the primary step to start sending events to Sentry. ```csharp var ravenClient = new RavenClient("https://public@sentry.io/project-id"); ``` -------------------------------- ### Register NoOpRavenClient with DI Source: https://context7.com/getsentry/raven-csharp/llms.txt Register a no-op client for development or testing environments where sending events to Sentry is not desired. This example uses Microsoft.Extensions.DependencyInjection. ```csharp using SharpRaven; using SharpRaven.Data; using Microsoft.Extensions.DependencyInjection; // example DI container // Register a no-op client in development / test var services = new ServiceCollection(); bool isDevelopment = true; if (isDevelopment) services.AddSingleton(); else services.AddSingleton( new RavenClient("https://public_key@sentry.io/project-id")); var provider = services.BuildServiceProvider(); var ravenClient = provider.GetRequiredService(); // In development this is a silent no-op; in production it sends to Sentry string id = ravenClient.Capture(new SentryEvent(new Exception("Test"))); Console.WriteLine(id); // returns a random GUID in no-op mode ``` -------------------------------- ### Instantiate RavenClient with DSN Source: https://context7.com/getsentry/raven-csharp/llms.txt Demonstrates the simplest way to instantiate RavenClient by passing the Sentry DSN directly. Also shows how to configure default metadata like Release, Environment, Logger, Timeout, and Compression. ```csharp using SharpRaven; using SharpRaven.Data; // Simplest form – DSN passed directly var client = new RavenClient("https://public_key@sentry.io/project-id"); // With optional metadata applied to every event var client2 = new RavenClient("https://public_key@sentry.io/project-id") { Release = "2.1.0", Environment = "production", Logger = "MyApp.ErrorLogger", Timeout = TimeSpan.FromSeconds(10), Compression = true // gzip the JSON payload }; client2.Tags["region"] = "eu-west-1"; // default tag on every event ``` -------------------------------- ### RavenClient Constructor Source: https://context7.com/getsentry/raven-csharp/llms.txt Demonstrates various ways to instantiate the RavenClient, including passing a DSN directly, configuring optional properties, and using background sending mode. ```APIDOC ## RavenClient — Constructor `RavenClient` is instantiated with a Sentry DSN string (or `Dsn` object). Optional factories allow customising JSON packet creation, HTTP request building, and user-context resolution. A `backgroundSending` overload (available on .NET 4.5+) queues events on a background thread so the calling thread is never blocked. ```csharp using SharpRaven; using SharpRaven.Data; // Simplest form – DSN passed directly var client = new RavenClient("https://public_key@sentry.io/project-id"); // With optional metadata applied to every event var client2 = new RavenClient("https://public_key@sentry.io/project-id") { Release = "2.1.0", Environment = "production", Logger = "MyApp.ErrorLogger", Timeout = TimeSpan.FromSeconds(10), Compression = true // gzip the JSON payload }; client2.Tags["region"] = "eu-west-1"; // default tag on every event // Background (non-blocking) mode – .NET 4.5+ only using (var bgClient = new RavenClient( new Dsn("https://public_key@sentry.io/project-id"), backgroundSending: true)) { // Events are dispatched on a background thread; Dispose() flushes the queue bgClient.Capture(new SentryEvent(new Exception("Background error"))); } ``` ``` -------------------------------- ### Configure RavenClient DSN via app.config/web.config Source: https://context7.com/getsentry/raven-csharp/llms.txt Illustrates how to configure the Sentry DSN in `app.config` or `web.config` under the `sharpRaven` section, allowing RavenClient to read it automatically without passing it to the constructor. ```xml
``` -------------------------------- ### Register DSN with TinyIoC Container Source: https://github.com/getsentry/raven-csharp/blob/develop/README.md Configure the DSN by registering an instance of the `Dsn` class within the TinyIoC container. This is for Nancy applications. ```csharp protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { container.Register(new Dsn("https://public@sentry.io/project-id")); } ``` -------------------------------- ### Inject IRavenClient in Nancy Module Source: https://github.com/getsentry/raven-csharp/blob/develop/README.md Demonstrates how to inject the `IRavenClient` into a Nancy module's constructor. This allows you to send events from within your Nancy application. ```csharp public class LoggingModule : NancyModule { private readonly IRavenClient ravenClient; public LoggingModule(IRavenClient ravenClient) { this.ravenClient = ravenClient; } } ``` -------------------------------- ### Nancy Integration Configuration Source: https://context7.com/getsentry/raven-csharp/llms.txt Configure SharpRaven.Nancy integration using app.config or web.config. This allows automatic capture of unhandled exceptions. ```xml
``` -------------------------------- ### Configure DSN via XML Configuration Source: https://github.com/getsentry/raven-csharp/blob/develop/README.md Set the DSN using XML configuration within the `sharpRaven` section. This method is an alternative to programmatic registration for Nancy applications. ```xml
``` -------------------------------- ### RavenClient DSN via Configuration Source: https://context7.com/getsentry/raven-csharp/llms.txt Shows how to configure the RavenClient to read the Sentry DSN from `app.config` or `web.config`. ```APIDOC ## RavenClient — DSN via app.config / web.config When no DSN is passed to the constructor, `RavenClient()` reads the DSN from the `sharpRaven` section in `app.config` or `web.config`. ```xml
``` ```csharp // DSN is read automatically from configuration var client = new RavenClient(); string eventId = client.Capture(new SentryEvent(new Exception("From config"))); Console.WriteLine("Sentry event ID: " + eventId); // "a1b2c3d4e5f6..." ``` ``` -------------------------------- ### Capture Exception from Configuration Source: https://context7.com/getsentry/raven-csharp/llms.txt Demonstrates capturing an exception using RavenClient when the DSN is automatically read from the application's configuration file (`app.config` or `web.config`). ```csharp // DSN is read automatically from configuration var client = new RavenClient(); string eventId = client.Capture(new SentryEvent(new Exception("From config"))); Console.WriteLine("Sentry event ID: " + eventId); // "a1b2c3d4e5f6..." ``` -------------------------------- ### Background Sending with RavenClient Source: https://context7.com/getsentry/raven-csharp/llms.txt Shows how to use the background sending mode for RavenClient, available on .NET 4.5+, which queues events on a background thread to avoid blocking the calling thread. Ensure Dispose() is called to flush the queue. ```csharp // Background (non-blocking) mode – .NET 4.5+ only using (var bgClient = new RavenClient( new Dsn("https://public_key@sentry.io/project-id"), backgroundSending: true)) { // Events are dispatched on a background thread; Dispose() flushes the queue bgClient.Capture(new SentryEvent(new Exception("Background error"))); } ``` -------------------------------- ### RavenClient.Capture Exception Source: https://context7.com/getsentry/raven-csharp/llms.txt Explains how to use the `Capture` method to send a `SentryEvent` (wrapping an exception) to Sentry, including attaching custom metadata. ```APIDOC ## RavenClient.Capture — Capture an Exception `string Capture(SentryEvent @event)` is the primary method for sending any event to Sentry. It accepts a `SentryEvent` that wraps an exception or a plain message and returns the Sentry event ID on success, or `null` on failure. ```csharp using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id") { Release = "1.4.2", Environment = "production" }; try { // ... code that may throw int result = int.Parse("not-a-number"); } catch (Exception ex) { // Attach custom metadata before capturing ex.Data["UserId"] = "usr_42"; ex.Data["RequestId"] = "req_99"; var sentryEvent = new SentryEvent(ex) { Level = ErrorLevel.Error, Extra = new { Component = "PaymentProcessor", Amount = 49.99 }, Fingerprint = { "payment-parse-failure" } }; sentryEvent.Tags["payment_gateway"] = "stripe"; string eventId = client.Capture(sentryEvent); // eventId is a 32-char hex string, e.g. "a1b2c3d4e5f6..." Console.WriteLine(eventId ?? "Capture failed"); } ``` ``` -------------------------------- ### Capture Exception with Custom Metadata Source: https://context7.com/getsentry/raven-csharp/llms.txt Shows how to capture an exception using `RavenClient.Capture` and attach custom metadata such as `UserId`, `RequestId`, `Level`, `Extra` data, `Fingerprint`, and `Tags` to the `SentryEvent` before sending it. ```csharp using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id") { Release = "1.4.2", Environment = "production" }; try { // ... code that may throw int result = int.Parse("not-a-number"); } catch (Exception ex) { // Attach custom metadata before capturing ex.Data["UserId"] = "usr_42"; ex.Data["RequestId"] = "req_99"; var sentryEvent = new SentryEvent(ex) { Level = ErrorLevel.Error, Extra = new { Component = "PaymentProcessor", Amount = 49.99 }, Fingerprint = { "payment-parse-failure" } }; sentryEvent.Tags["payment_gateway"] = "stripe"; string eventId = client.Capture(sentryEvent); // eventId is a 32-char hex string, e.g. "a1b2c3d4e5f6..." Console.WriteLine(eventId ?? "Capture failed"); } ``` -------------------------------- ### CaptureAsync Event ( .NET 4.5+) Source: https://context7.com/getsentry/raven-csharp/llms.txt Use CaptureAsync for asynchronous event capturing in .NET 4.5 and later. It returns a Task containing the event ID. Ensure the RavenClient is initialized with your Sentry DSN. ```csharp using System.Threading.Tasks; using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id"); public async Task ProcessOrderAsync(Order order) { try { await _orderService.ProcessAsync(order); } catch (Exception ex) { var sentryEvent = new SentryEvent(ex) { Level = ErrorLevel.Fatal, Extra = new { OrderId = order.Id, CustomerId = order.CustomerId } }; string eventId = await client.CaptureAsync(sentryEvent); _logger.Error("Sentry event captured: {EventId}", eventId); throw; // re-throw after capture } } ``` -------------------------------- ### Async Capture Method Signature Source: https://github.com/getsentry/raven-csharp/blob/develop/README.md This is the signature for the asynchronous capture method available in the .NET 4.5 or later build of SharpRaven. It returns a Task that completes with a string. ```csharp async Task CaptureAsync(SentryEvent @event); ``` -------------------------------- ### SendUserFeedback Source: https://context7.com/getsentry/raven-csharp/llms.txt `SendUserFeedback` and `SendUserFeedbackAsync` are methods used to submit user-supplied feedback that is associated with a previously captured Sentry event ID. ```APIDOC ## SendUserFeedback — Submitting User Feedback `SendUserFeedback` / `SendUserFeedbackAsync` submits user-supplied feedback tied to a previously captured Sentry event ID. ```csharp using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id"); // First capture an exception to get an event ID string eventId = client.Capture(new SentryEvent(new Exception("Crash!"))); // Then associate user feedback with that event var feedback = new SentryUserFeedback { EventID = eventId, Name = "Alice Smith", Email = "alice@example.com", Comments = "The app crashed when I clicked Save on the profile page." }; string result = client.SendUserFeedback(feedback); // Empty string = success; non-empty = server error response // Async variant (.NET 4.5+) string asyncResult = await client.SendUserFeedbackAsync(feedback); ``` ``` -------------------------------- ### BeforeSend Hook Source: https://context7.com/getsentry/raven-csharp/llms.txt The `BeforeSend` hook is a `Func` that is invoked just before an HTTP request is sent. It enables inspection or replacement of the requester, which is useful for logging, stubbing in tests, or adding custom HTTP headers. ```APIDOC ## BeforeSend — Intercepting / Modifying the Request `BeforeSend` is a `Func` hook invoked immediately before the HTTP request is sent. It allows inspecting or replacing the requester, which is useful for logging, stubbing in tests, or adding custom HTTP headers. ```csharp using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id"); // Log raw JSON before send (useful for debugging) client.BeforeSend = requester => { if (requester is HttpRequester http) Console.WriteLine("Sending: " + http.Data?.Raw); return requester; }; // Return null / throw to suppress sending (e.g. in tests) client.BeforeSend = requester => null; // suppresses the request ``` ``` -------------------------------- ### SentryEvent Model Construction Source: https://context7.com/getsentry/raven-csharp/llms.txt Construct SentryEvent objects to capture exceptions or messages with custom levels, extra data, and fingerprints for grouping. Tags can be added to categorize events. ```csharp using SharpRaven.Data; // Exception-based event var exceptionEvent = new SentryEvent(new InvalidOperationException("State error")) { Level = ErrorLevel.Error, // Fatal | Error | Warning | Info | Debug Message = "User triggered invalid state transition", Extra = new { WorkflowStep = "checkout", CartItems = 3 }, Fingerprint = { "checkout", "invalid-state" } // custom grouping }; exceptionEvent.Tags["tenant"] = "acme-corp"; // Message-only event (no exception) var messageEvent = new SentryEvent(new SentryMessage("Deployment completed: {0} → {1}", "v1.3", "v1.4")) { Level = ErrorLevel.Info }; messageEvent.Tags["deploy_env"] = "production"; // Capture both var client = new RavenClient("https://public_key@sentry.io/project-id"); client.Capture(exceptionEvent); client.Capture(messageEvent); ``` -------------------------------- ### Handle Internal Client Errors with ErrorOnCapture Source: https://context7.com/getsentry/raven-csharp/llms.txt Customize the handling of internal errors that occur within the SharpRaven client during the capture process. By default, these errors are written to the console. ```csharp using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id"); client.ErrorOnCapture = ex => { // Route internal SharpRaven errors to your own logger MyLogger.Warn("SharpRaven failed to send event", ex); }; // Now any network or serialisation failure is forwarded to MyLogger client.Capture(new SentryEvent(new Exception("Test"))); ``` -------------------------------- ### Capture Exception in Catch Block Source: https://github.com/getsentry/raven-csharp/blob/develop/README.md Use this snippet within a catch block to capture and send an exception to Sentry. Ensure the RavenClient is instantiated before use. ```csharp try { int i2 = 0; int i = 10 / i2; } catch (Exception exception) { ravenClient.Capture(new SentryEvent(exception)); } ``` -------------------------------- ### Manually Set User Context for Events Source: https://context7.com/getsentry/raven-csharp/llms.txt Include user identity in non-web scenarios by manually setting user context. This can be done via extra data in the SentryEvent, or by providing a custom ISentryUserFactory. ```csharp using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id"); // Override the auto-detected user on a specific event var packet = new SentryEvent(new Exception("Permission denied")) { Level = ErrorLevel.Warning }; // Manually attach user context via BeforeSend / JsonPacket post-processing // by providing a custom ISentryUserFactory: // new RavenClient(dsn, sentryUserFactory: new MyUserFactory()) // Or capture with runtime user info via extra data: packet.Extra = new { user_id = "usr_42", user_name = "alice", user_email = "alice@example.com", ip_address = "10.0.0.1" }; client.Capture(packet); ``` -------------------------------- ### Inspect or Modify Data Before Sending Source: https://github.com/getsentry/raven-csharp/blob/develop/README.md Hook into the `BeforeSend` event to inspect or modify the data being sent to Sentry. You can return the original requester or a modified version. ```csharp ravenClient.BeforeSend = requester => { // Here you can log data from the requester // or replace it entirely if you want. return requester; }; ``` -------------------------------- ### Intercept HTTP Requests with BeforeSend Source: https://context7.com/getsentry/raven-csharp/llms.txt Use the BeforeSend hook to inspect or modify the HTTP request before it's sent. This is useful for debugging by logging the raw data or for suppressing requests in tests by returning null. ```csharp using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id"); // Log raw JSON before send (useful for debugging) client.BeforeSend = requester => { if (requester is HttpRequester http) Console.WriteLine("Sending: " + http.Data?.Raw); return requester; }; // Return null / throw to suppress sending (e.g. in tests) client.BeforeSend = requester => null; // suppresses the request ``` -------------------------------- ### SentryMessage Parameterized Messages Source: https://context7.com/getsentry/raven-csharp/llms.txt Use SentryMessage for parameterized logging, allowing formatted strings with optional parameters. It supports implicit conversion from plain strings. ```csharp using SharpRaven.Data; // Parameterised construction var msg1 = new SentryMessage("User {0} logged in from {1}", "alice", "192.168.1.1"); Console.WriteLine(msg1.ToString()); // "User alice logged in from 192.168.1.1" // Implicit conversion from string SentryMessage msg2 = "Simple string message"; // Use as a standalone event var client = new RavenClient("https://public_key@sentry.io/project-id"); client.Capture(new SentryEvent(msg1) { Level = ErrorLevel.Info }); ``` -------------------------------- ### Custom Error Handling for Capture Failures Source: https://github.com/getsentry/raven-csharp/blob/develop/README.md Customize the behavior when an error occurs during the capture process by assigning a delegate to the `ErrorOnCapture` property. This allows for custom logging or error handling. ```csharp ravenClient.ErrorOnCapture = exception => { // Custom code here }; ``` -------------------------------- ### RavenClient.CaptureAsync Source: https://context7.com/getsentry/raven-csharp/llms.txt Captures a SentryEvent asynchronously. This method is available on .NET 4.5 and later targets and returns a Task with the event ID. ```APIDOC ## RavenClient.CaptureAsync ### Description Captures a SentryEvent asynchronously. This method is available on .NET 4.5 and later targets and returns a Task with the event ID. ### Method Signature `Task CaptureAsync(SentryEvent @event)` ### Parameters - **@event** (SentryEvent) - Required - The SentryEvent object to capture. ### Returns - **Task** - A task that represents the asynchronous operation, containing the event ID of the captured event. ### Example ```csharp using System.Threading.Tasks; using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id"); public async Task ProcessOrderAsync(Order order) { try { await _orderService.ProcessAsync(order); } catch (Exception ex) { var sentryEvent = new SentryEvent(ex) { Level = ErrorLevel.Fatal, Extra = new { OrderId = order.Id, CustomerId = order.CustomerId } }; string eventId = await client.CaptureAsync(sentryEvent); _logger.Error("Sentry event captured: {EventId}", eventId); throw; // re-throw after capture } } ``` ``` -------------------------------- ### Add Extra Data to Exception Source: https://github.com/getsentry/raven-csharp/blob/develop/README.md Augment captured exceptions with additional key-value data by adding entries to the exception's `Data` property. This data will appear in the 'extra' section in Sentry. ```csharp try { // ... } catch (Exception exception) { exception.Data.Add("SomeKey", "SomeValue"); throw; } ``` -------------------------------- ### Log Non-Exception Message Source: https://github.com/getsentry/raven-csharp/blob/develop/README.md Capture and send a simple message to Sentry without it being tied to an exception. Useful for logging informational events. ```csharp ravenClient.Capture(new SentryEvent("Hello World!")); ``` -------------------------------- ### ErrorOnCapture Handler Source: https://context7.com/getsentry/raven-csharp/llms.txt `ErrorOnCapture` is an `Action` that is called whenever the `Capture` method encounters an internal error, such as a network issue. By default, these errors are written to the console, but a custom handler can be assigned to integrate with your own logging infrastructure. ```APIDOC ## ErrorOnCapture — Handling Internal Errors `ErrorOnCapture` is an `Action` called whenever `Capture` itself throws internally (e.g. network error). By default errors are written to `Console`. Assign a custom handler to integrate with your own logging infrastructure. ```csharp using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id"); client.ErrorOnCapture = ex => { // Route internal SharpRaven errors to your own logger MyLogger.Warn("SharpRaven failed to send event", ex); }; // Now any network or serialisation failure is forwarded to MyLogger client.Capture(new SentryEvent(new Exception("Test"))); ``` ``` -------------------------------- ### SentryUser Context Source: https://context7.com/getsentry/raven-csharp/llms.txt `SentryUser` provides user context that is automatically attached to every event when an HTTP context is present. It can also be manually set to include user identity in non-web scenarios. ```APIDOC ## SentryUser — User Context `SentryUser` is attached automatically to every event when an HTTP context is present. It can also be set manually to include user identity in non-web scenarios. ```csharp using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id"); // Override the auto-detected user on a specific event var packet = new SentryEvent(new Exception("Permission denied")) { Level = ErrorLevel.Warning }; // Manually attach user context via BeforeSend / JsonPacket post-processing // by providing a custom ISentryUserFactory: // new RavenClient(dsn, sentryUserFactory: new MyUserFactory()) // Or capture with runtime user info via extra data: packet.Extra = new { user_id = "usr_42", user_name = "alice", user_email = "alice@example.com", ip_address = "10.0.0.1" }; client.Capture(packet); ``` ``` -------------------------------- ### SentryEvent Model Source: https://context7.com/getsentry/raven-csharp/llms.txt Represents an event to be sent to Sentry. It can wrap an Exception or a SentryMessage and includes properties for level, tags, fingerprints, extra data, and breadcrumbs. ```APIDOC ## SentryEvent ### Description `SentryEvent` is the central data object passed to `Capture` / `CaptureAsync`. It can wrap an `Exception` or a `SentryMessage`, and exposes properties for level, tags, fingerprints, extra data, and breadcrumbs. ### Properties - **Level** (ErrorLevel) - The severity level of the event (e.g., Fatal, Error, Warning, Info, Debug). - **Message** (string) - A descriptive message for the event. - **Extra** (object) - An object containing additional contextual data. - **Fingerprint** (List) - A list of strings used for custom event grouping. - **Tags** (Dictionary) - A dictionary for key-value tags associated with the event. ### Example (Exception-based event) ```csharp using SharpRaven.Data; var exceptionEvent = new SentryEvent(new InvalidOperationException("State error")) { Level = ErrorLevel.Error, Message = "User triggered invalid state transition", Extra = new { WorkflowStep = "checkout", CartItems = 3 }, Fingerprint = { "checkout", "invalid-state" } // custom grouping }; exceptionEvent.Tags["tenant"] = "acme-corp"; ``` ### Example (Message-only event) ```csharp using SharpRaven.Data; var messageEvent = new SentryEvent(new SentryMessage("Deployment completed: {0} → {1}", "v1.3", "v1.4")) { Level = ErrorLevel.Info }; messageEvent.Tags["deploy_env"] = "production"; ``` ### Example (Capturing events) ```csharp var client = new RavenClient("https://public_key@sentry.io/project-id"); client.Capture(exceptionEvent); client.Capture(messageEvent); ``` ``` -------------------------------- ### Configure LogScrubber with Custom Filters Source: https://context7.com/getsentry/raven-csharp/llms.txt Attach a LogScrubber to redact sensitive data from outgoing payloads. You can add custom filters, such as one for Social Security Numbers, to the default filters. ```csharp using SharpRaven; using SharpRaven.Logging; var client = new RavenClient("https://public_key@sentry.io/project-id"); // Attach the default scrubber (redacts credit cards + US phone numbers) client.LogScrubber = new LogScrubber(); // Add a custom filter that removes SSNs client.LogScrubber = new LogScrubber(); ((LogScrubber)client.LogScrubber).Filters.Add( new SharpRaven.Logging.Filters.SocialSecurityFilter()); try { throw new Exception("Card 4111111111111111 declined for user john@example.com"); } catch (Exception ex) { // The credit card number is scrubbed before the payload leaves the machine client.Capture(new SentryEvent(ex)); } ``` -------------------------------- ### SentryMessage Model Source: https://context7.com/getsentry/raven-csharp/llms.txt Represents a parameterized message for Sentry events. It can be constructed with a format string and parameters, or implicitly converted from a plain string. ```APIDOC ## SentryMessage ### Description `SentryMessage` captures a format string and optional parameters. It implicitly converts from `string`, so plain strings can be used anywhere a `SentryMessage` is expected. ### Example (Parameterized construction) ```csharp using SharpRaven.Data; var msg1 = new SentryMessage("User {0} logged in from {1}", "alice", "192.168.1.1"); Console.WriteLine(msg1.ToString()); // "User alice logged in from 192.168.1.1" ``` ### Example (Implicit conversion from string) ```csharp SentryMessage msg2 = "Simple string message"; ``` ### Example (Use as a standalone event) ```csharp var client = new RavenClient("https://public_key@sentry.io/project-id"); client.Capture(new SentryEvent(msg1) { Level = ErrorLevel.Info }); ``` ``` -------------------------------- ### Breadcrumbs - AddTrail / RestartTrails Source: https://context7.com/getsentry/raven-csharp/llms.txt Manages breadcrumbs, which record a trail of events leading up to a captured error. Breadcrumbs are automatically attached to the next Capture call and then cleared. ```APIDOC ## Breadcrumbs — AddTrail / RestartTrails ### Description Breadcrumbs record a trail of events leading up to a captured error. Up to 100 breadcrumbs are stored in a circular buffer on the client; they are attached to the next `Capture` call and then the buffer is cleared automatically. ### Methods - **AddTrail(Breadcrumb breadcrumb)**: Adds a breadcrumb to the trail. - **RestartTrails()**: Manually discards breadcrumbs without capturing. ### Breadcrumb Properties - **Type** (BreadcrumbType): The type of the breadcrumb (e.g., Navigation, Query, User, Manual). - **Message** (string): A descriptive message for the breadcrumb. - **Level** (BreadcrumbLevel): The severity level of the breadcrumb (e.g., Info, Debug, Warning, Error). - **Data** (Dictionary): Additional key-value data associated with the breadcrumb. ### Example ```csharp using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id"); // Record navigation / action trail client.AddTrail(new Breadcrumb("auth") { Type = BreadcrumbType.Navigation, Message = "User logged in", Level = BreadcrumbLevel.Info, Data = new Dictionary { ["username"] = "alice" } }); client.AddTrail(new Breadcrumb("db") { Type = BreadcrumbType.Query, Message = "SELECT * FROM orders WHERE user_id = ?", Level = BreadcrumbLevel.Debug }); try { // ... throws throw new TimeoutException("Database connection timed out"); } catch (Exception ex) { // Breadcrumbs above are automatically attached to this event string id = client.Capture(new SentryEvent(ex)); // After Capture, trail is automatically reset via RestartTrails() } // Manually discard breadcrumbs without capturing client.RestartTrails(); ``` ``` -------------------------------- ### LogScrubber Source: https://context7.com/getsentry/raven-csharp/llms.txt The LogScrubber class scrubs sensitive data from JSON payloads before they are sent to Sentry. It includes built-in filters for credit card numbers and US phone numbers, and allows for custom filters to be added. ```APIDOC ## LogScrubber — Removing Sensitive Data `LogScrubber` scrubs the serialised JSON payload before it is sent to Sentry. The built-in implementation redacts credit card numbers and US phone numbers. Custom filters can be added by appending to `LogScrubber.Filters`. ```csharp using SharpRaven; using SharpRaven.Logging; var client = new RavenClient("https://public_key@sentry.io/project-id"); // Attach the default scrubber (redacts credit cards + US phone numbers) client.LogScrubber = new LogScrubber(); // Add a custom filter that removes SSNs client.LogScrubber = new LogScrubber(); ((LogScrubber)client.LogScrubber).Filters.Add( new SharpRaven.Logging.Filters.SocialSecurityFilter()); try { throw new Exception("Card 4111111111111111 declined for user john@example.com"); } catch (Exception ex) { // The credit card number is scrubbed before the payload leaves the machine client.Capture(new SentryEvent(ex)); } ``` ``` -------------------------------- ### Breadcrumbs Trail Recording Source: https://context7.com/getsentry/raven-csharp/llms.txt Record a trail of events using AddTrail before capturing an error. Breadcrumbs are automatically attached to the next Capture call and the buffer is cleared. Use RestartTrails to manually discard breadcrumbs. ```csharp using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id"); // Record navigation / action trail client.AddTrail(new Breadcrumb("auth") { Type = BreadcrumbType.Navigation, Message = "User logged in", Level = BreadcrumbLevel.Info, Data = new Dictionary { ["username"] = "alice" } }); client.AddTrail(new Breadcrumb("db") { Type = BreadcrumbType.Query, Message = "SELECT * FROM orders WHERE user_id = ?", Level = BreadcrumbLevel.Debug }); try { // ... throws throw new TimeoutException("Database connection timed out"); } catch (Exception ex) { // Breadcrumbs above are automatically attached to this event string id = client.Capture(new SentryEvent(ex)); // After Capture, trail is automatically reset via RestartTrails() } // Manually discard breadcrumbs without capturing client.RestartTrails(); ``` -------------------------------- ### Submit User Feedback with Event ID Source: https://context7.com/getsentry/raven-csharp/llms.txt Send user-supplied feedback associated with a specific Sentry event ID. The SendUserFeedback method returns an empty string on success or a server error message on failure. An async variant is available for .NET 4.5+. ```csharp using SharpRaven; using SharpRaven.Data; var client = new RavenClient("https://public_key@sentry.io/project-id"); // First capture an exception to get an event ID string eventId = client.Capture(new SentryEvent(new Exception("Crash!"))); // Then associate user feedback with that event var feedback = new SentryUserFeedback { EventID = eventId, Name = "Alice Smith", Email = "alice@example.com", Comments = "The app crashed when I clicked Save on the profile page." }; string result = client.SendUserFeedback(feedback); // Empty string = success; non-empty = server error response // Async variant (.NET 4.5+) string asyncResult = await client.SendUserFeedbackAsync(feedback); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.