### Add Raygun4Net.AspNetCore Package Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Install the Raygun4Net.AspNetCore NuGet package using the .NET CLI. ```bash dotnet add package Mindscape.Raygun4Net.AspNetCore ``` -------------------------------- ### Install Raygun4Net.WebApi NuGet Package Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.WebApi/README.md Use the dotnet CLI to add the Raygun4Net.WebApi package to your project. ```bash dotnet add package Mindscape.Raygun4Net.WebApi ``` -------------------------------- ### Add Mindscape.Raygun4Net.NetCore NuGet Package Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.NetCore/README.md Install the Raygun4Net.NetCore NuGet package using the dotnet CLI. ```bash dotnet add package Mindscape.Raygun4Net.NetCore ``` -------------------------------- ### Add Raygun Logging Package Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.Extensions.Logging/README.md Install the Mindscape.Raygun4Net.Extensions.Logging NuGet package using the dotnet CLI. ```csharp dotnet add package Mindscape.Raygun4Net.Extensions.Logging ``` -------------------------------- ### Configure Raygun API Key in Web.config Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Reference the RaygunSettings tag after configSections and provide your API key. This is a basic setup. ```xml ``` -------------------------------- ### Add Raygun4Net NuGet Package Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Use the dotnet CLI to add the Raygun4Net NuGet package to your project. This is the primary installation step for most .NET projects. ```sh dotnet add package Mindscape.Raygun4Net ``` -------------------------------- ### Install Raygun Core Packages Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.Extensions.Logging/README.md Ensure the core Raygun package is installed. For ASP.NET Core applications, install Mindscape.Raygun4Net.AspNetCore. For .NET Core service applications, install Mindscape.Raygun4Net.NetCore. ```csharp // If you're using it in an ASP.NET Core application: dotnet add package Mindscape.Raygun4Net.AspNetCore // If you're using it in a .NET Core service application: dotnet add package Mindscape.Raygun4Net.NetCore ``` -------------------------------- ### Configure Raygun in JobHostConfiguration Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.Azure.WebJob/README.md Add this call to your JobHostConfiguration setup to automatically send unhandled exceptions to Raygun. You can optionally pass a pre-configured RaygunClient instance for further customization. ```csharp config.UseRaygun(); ``` -------------------------------- ### Manually Send Exception with RaygunClient Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Inject RaygunClient into controllers or services to manually send exceptions. This example demonstrates sending an exception caught within a try-catch block. ```csharp public class MyController : Controller { private readonly RaygunClient _raygunClient; public MyController(RaygunClient raygunClient) { _raygunClient = raygunClient; } public async Task TestManualError() { try { throw new Exception("Test from .NET Core MVC app"); } catch (Exception ex) { await _raygunClient.SendInBackground(ex); } return View(); } } ``` -------------------------------- ### Initialize RaygunClient with API Key and Unhandled Exception Delegate Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.NetCore/README.md Create a RaygunClient instance with your API key and hook it up to the unhandled exception delegate in your application's entry point (e.g., Program.cs). ```csharp using Mindscape.Raygun4Net; private static RaygunClient _raygunClient = new RaygunClient("paste_your_api_key_here"); AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => _raygunClient.Send(e.ExceptionObject as Exception); ``` -------------------------------- ### WinRT Application Initialization with RaygunClient.Attach Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Call the static RaygunClient.Attach method with your API key in the application's main entry point to enable automatic exception handling. ```csharp public App() { RaygunClient.Attach("YOUR_APP_API_KEY"); } ``` -------------------------------- ### Enable TLS 1.2 and TLS 1.3 for older .NET Frameworks Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md For .NET 3.5 or earlier, explicitly enable TLS 1.2 and TLS 1.3 in your application's startup code to ensure secure communication with Raygun's ingestion nodes. ```csharp protected void Application_Start() { // Enable TLS 1.2 and TLS 1.3 ServicePointManager.SecurityProtocol |= ( (SecurityProtocolType)3072 /*TLS 1.2*/ | (SecurityProtocolType)12288 /*TLS 1.3*/ ); } ``` -------------------------------- ### Provide Custom RaygunWebApiClient Instance Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.WebApi/README.md Use the overload of RaygunWebApiClient.Attach that accepts a function to configure and return a custom client instance for advanced options. ```csharp RaygunWebApiClient.Attach(config, () => { var client = new RaygunWebApiClient(); client.ApplicationVersion = "5.9.0.1"; client.UserInfo = new RaygunIdentifierMessage("user@example.com"); client.SendingMessage += (sender, args) => { if (args.Message.Details.MachineName == "BadServer") { args.Cancel = true; } }; return client; }); ``` -------------------------------- ### Configure Raygun4Net Settings in C# Source: https://context7.com/mindscapehq/raygun4net/llms.txt Use this configuration block within your service registration to set up Raygun4Net. Ensure you replace 'YOUR_APP_API_KEY' with your actual API key. Various options are available for customizing error reporting, data scrubbing, and more. ```csharp services.AddRaygun(settings => { settings.ApiKey = "YOUR_APP_API_KEY"; // Required settings.ApiEndpoint = new Uri("https://api.raygun.com/entries"); // Default endpoint settings.ApplicationVersion = "1.0.0.0"; // Overrides assembly version settings.ThrowOnError = false; // Bubble Raygun errors up (useful for debugging) settings.ExcludeErrorsFromLocal = true; // Suppress reports from localhost settings.ExcludedStatusCodes = new[] { 404, 503 }; // HTTP status codes to suppress // Sensitive data scrubbing settings.IgnoreSensitiveFieldNames = new[] { "*password*", "*token*" }; // All fields settings.IgnoreQueryParameterNames = new[] { "api_key" }; settings.IgnoreFormFieldNames = new[] { "creditCard" }; settings.IgnoreHeaderNames = new[] { "Authorization" }; settings.IgnoreCookieNames = new[] { "session" }; settings.IsRawDataIgnored = false; // true = never send raw request body settings.UseXmlRawDataFilter = true; settings.UseKeyValuePairRawDataFilter = true; settings.IsRawDataIgnoredWhenFilteringFailed = true; // Background processing settings.BackgroundMessageWorkerCount = 4; // Defaults to min(ProcessorCount*2, 8) settings.BackgroundMessageWorkerBreakpoint = 25; // Messages per worker threshold // Breadcrumbs settings.BreadcrumbsLevel = RaygunBreadcrumbLevel.Info; settings.BreadcrumbsLocationRecordingEnabled = false; // true adds class/method (performance cost) // Offline storage settings.MaxCrashReportsStoredOffline = 50; // Hard limit: 64 settings.CrashReportingOfflineStorageEnabled = true; // Logging settings.LogLevel = RaygunLogLevel.Warning; }); ``` -------------------------------- ### Configure Raygun Services (appsettings.json) Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Configure Raygun by referencing settings from appsettings.json. Ensure the RaygunSettings section with an ApiKey is present in your configuration file. ```csharp public void ConfigureServices(IServiceCollection services) { // Assumes you're configuring Raygun in appsettings.json services.AddRaygun(Configuration); // Or if you're configuring Raygun in code services.AddRaygun(settings => { settings.ApiKey = "YOUR_APP_API_KEY"; ... }); } ``` -------------------------------- ### Configure RaygunClient with Offline Storage Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.NetCore/README.md Demonstrates how to configure the RaygunClient with a timer-based send strategy and local application data storage for offline crash reports. Ensure you replace 'paste_your_api_key_here' with your actual Raygun API key. ```csharp // Attempt to send any offline crash reports every 30 seconds var sendStrategy = new TimerBasedSendStrategy(TimeSpan.FromSeconds(30)); // Store crash reports in Local AppData var offlineStore = new LocalApplicationDataCrashReportStore(sendStrategy); var raygunClient = new RaygunClient(new RaygunSettings() { ApiKey = "paste_your_api_key_here", // Optionally store OfflineStore = offlineStore }); ``` -------------------------------- ### Configure Raygun Settings in Code Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Configure Raygun settings programmatically using the AddRaygun extension method. ```csharp services.AddRaygun(settings => { settings.ApiKey = "YOUR_APP_API_KEY"; settings.ExcludeErrorsFromLocal = true; }); ``` -------------------------------- ### Configure Raygun4Net.AspNetCore with appsettings.json Source: https://context7.com/mindscapehq/raygun4net/llms.txt Configure Raygun settings in appsettings.json for ASP.NET Core applications. ```json { "RaygunSettings": { "ApiKey": "YOUR_APP_API_KEY", "ExcludeErrorsFromLocal": true, "ExcludedStatusCodes": [404, 418], "ApplicationVersion": "2.1.0" } } ``` -------------------------------- ### Register WebApiConfig in Global.asax.cs Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.WebApi/README.md Ensure your WebApiConfig is registered in the Application_Start method of your Global.asax.cs file. ```csharp protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); } ``` -------------------------------- ### Enable TLS 1.1 and TLS 1.2 Configuration Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.WebApi/README.md Update your Global.asax.cs to enable required TLS protocols for Raygun's ingestion nodes, especially for older .NET versions. ```csharp protected void Application_Start() { // Enable TLS 1.1 and TLS 1.2 with future support for TLS 3 ServicePointManager.SecurityProtocol |= (SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls3 ); } ``` -------------------------------- ### Implement Custom User Provider in ASP.NET Core Source: https://context7.com/mindscapehq/raygun4net/llms.txt Create a custom IRaygunUserProvider to resolve user information per-request using dependency injection in ASP.NET Core. Register the provider using AddRaygunUserProvider. ```csharp // ASP.NET Core: custom IRaygunUserProvider resolved per-request via DI using Mindscape.Raygun4Net.AspNetCore; public class ClaimsUserProvider : IRaygunUserProvider { private readonly IHttpContextAccessor _httpContextAccessor; public ClaimsUserProvider(IHttpContextAccessor httpContextAccessor) { _httpContextAccessor = httpContextAccessor; } public RaygunIdentifierMessage? GetUser() { var identity = _httpContextAccessor.HttpContext?.User?.Identity as ClaimsIdentity; if (identity?.IsAuthenticated != true) return null; var userId = identity.FindFirst(ClaimTypes.NameIdentifier)?.Value; var email = identity.FindFirst(ClaimTypes.Email)?.Value; var name = identity.FindFirst(ClaimTypes.Name)?.Value; return new RaygunIdentifierMessage(userId) { IsAnonymous = false, Email = email, FullName = name }; } } // Registration in Program.cs builder.Services.AddRaygunUserProvider(); ``` -------------------------------- ### Configure Raygun Settings in appsettings.json Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Configure Raygun settings, including API key and error exclusion rules, directly in the appsettings.json file. ```json { "RaygunSettings": { "ApiKey": "YOUR_APP_API_KEY", "ExcludeErrorsFromLocal": true } } ``` -------------------------------- ### Configure Raygun Logging in appsettings.json Source: https://context7.com/mindscapehq/raygun4net/llms.txt Alternatively, configure Raygun logging settings, including minimum log level and exception logging behavior, directly within the appsettings.json file. ```json // appsettings.json — alternative configuration { "RaygunSettings": { "ApiKey": "YOUR_APP_API_KEY", "MinimumLogLevel": "Warning", "OnlyLogExceptions": false } } ``` -------------------------------- ### Configure Raygun Logger in ASP.NET Core Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.Extensions.Logging/README.md Register the Raygun Client and Logger provider in an ASP.NET Core application's Program.cs or Startup.cs. The API key is required for settings. Optionally, register the Raygun User Provider. ```csharp using Mindscape.Raygun4Net.AspNetCore; using Mindscape.Raygun4Net.Extensions.Logging; var builder = WebApplication.CreateBuilder(args); // Registers the Raygun Client for AspNetCore builder.Services.AddRaygun(settings => { settings.ApiKey = "*your api key*"; }); // (Optional) Registers the Raygun User Provider builder.Services.AddRaygunUserProvider(); // Registers the Raygun Logger for use in MS Logger builder.Logging.AddRaygunLogger(); var app = builder.Build(); ``` -------------------------------- ### Configure Raygun Logger Options in Code Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.Extensions.Logging/README.md Customize Raygun logging behavior by setting MinimumLogLevel and OnlyLogExceptions directly in code. MinimumLogLevel defaults to LogLevel.Error, and OnlyLogExceptions defaults to true. ```csharp builder.Logging.AddRaygunLogger(options: options => { options.MinimumLogLevel = LogLevel.Information; options.OnlyLogExceptions = false; }); ``` -------------------------------- ### Configure RaygunSettings in Web.config Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.WebApi/README.md Add the RaygunSettings section to your Web.config file and provide your API key. ```xml
``` ```xml ``` -------------------------------- ### Xamarin for Android Initialization with RaygunClient.Attach Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Use the static RaygunClient.Attach method in the main Activity to enable automatic exception handling for Xamarin.Android applications. ```csharp RaygunClient.Attach("YOUR_APP_API_KEY"); ``` -------------------------------- ### Configure Raygun Logger Options in appsettings.json Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.Extensions.Logging/README.md Configure Raygun logging settings, such as MinimumLogLevel and OnlyLogExceptions, within the appsettings.json file under the "RaygunSettings" key. ```json { "RaygunSettings": { "MinimumLogLevel": "Information", "OnlyLogExceptions": false } } ``` -------------------------------- ### Configure RaygunSettings in appsettings.json Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Add Raygun API key to your application's configuration file. Ensure this file is correctly loaded by your application. ```json { "RaygunSettings": { "ApiKey": "YOUR_APP_API_KEY" } } ``` -------------------------------- ### Implement Custom Raygun User Provider Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Implement the IRaygunUserProvider interface to provide custom user information to Raygun. Requires IHttpContextAccessor for accessing request context. ```csharp public class ExampleUserProvider : IRaygunUserProvider { private readonly IHttpContextAccessor _contextAccessor; public ExampleUserProvider(IHttpContextAccessor httpContextAccessor) { _contextAccessor = contextAccessor; } public RaygunIdentifierMessage? GetUser() { var ctx = _contextAccessor.HttpContext; if (ctx == null) { return null; } var identity = ctx.User.Identity as ClaimsIdentity; if (identity?.IsAuthenticated == true) { return new RaygunIdentifierMessage(identity.Name) { IsAnonymous = false }; return null; } } ``` -------------------------------- ### RaygunClient.Send / SendAsync / SendInBackground Source: https://context7.com/mindscapehq/raygun4net/llms.txt Manually report a caught exception to Raygun. Send is synchronous, SendAsync is the preferred async method, and SendInBackground queues the report for background delivery. ```APIDOC ## `RaygunClient.Send` / `SendAsync` / `SendInBackground` — Sending Exceptions Manually Manually report a caught exception to Raygun. `Send` is synchronous, `SendAsync` is the preferred async method, and `SendInBackground` queues the report for background delivery (best for handled exceptions that won't crash the app). ```csharp // ASP.NET Core: inject RaygunClient via DI public class OrderController : Controller { private readonly RaygunClient _raygunClient; public OrderController(RaygunClient raygunClient) { _raygunClient = raygunClient; } [HttpPost("process")] public async Task ProcessOrder(OrderRequest request) { try { var result = await _orderService.ProcessAsync(request); return Ok(result); } catch (PaymentDeclinedException ex) { // Send with tags and custom diagnostic data await _raygunClient.SendAsync( ex, tags: new List { "payment", "order-processing" }, userCustomData: new Dictionary { { "OrderId", request.OrderId }, { "CustomerId", request.CustomerId }, { "Amount", request.Amount } } ); return StatusCode(402, "Payment declined"); } catch (Exception ex) { // Fire-and-forget background send for non-fatal errors await _raygunClient.SendInBackground(ex); return StatusCode(500); } } } // .NET Core / Console: direct client usage try { RunCriticalOperation(); } catch (Exception ex) { await raygunClient.SendAsync( ex, tags: new List { "background-job", "critical" }, userCustomData: new Dictionary { { "JobId", jobId } } ); } ``` ``` -------------------------------- ### Configure Raygun4Net for ASP.NET Framework (Web.config) Source: https://context7.com/mindscapehq/raygun4net/llms.txt Configure Raygun settings and the HTTP module in Web.config for ASP.NET Framework applications. ```xml
``` -------------------------------- ### Configure Raygun4Net.AspNetCore in Program.cs Source: https://context7.com/mindscapehq/raygun4net/llms.txt Register and configure Raygun services in Program.cs for ASP.NET Core. You can use configuration from appsettings.json or set settings directly in code. Optionally, enable default user tracking. ```csharp using Mindscape.Raygun4Net.AspNetCore; var builder = WebApplication.CreateBuilder(args); // Register Raygun with configuration from appsettings.json builder.Services.AddRaygun(builder.Configuration); // Or configure entirely in code builder.Services.AddRaygun(settings => { settings.ApiKey = "YOUR_APP_API_KEY"; settings.ExcludeErrorsFromLocal = true; settings.ExcludedStatusCodes = new[] { 404 }; }); // (Optional) Enable default user tracking from HttpContext.User builder.Services.AddRaygunUserProvider(); var app = builder.Build(); // Register middleware — place before other exception handlers app.UseRaygun(); app.MapGet("/throw", () => throw new InvalidOperationException("Unhandled pipeline exception")); app.Run(); // All unhandled exceptions are now automatically sent to Raygun ``` -------------------------------- ### Configure Raygun4Net.NetCore for Exception Handling Source: https://context7.com/mindscapehq/raygun4net/llms.txt Configure Raygun client for .NET Core applications. This can be done manually by hooking into AppDomain.CurrentDomain.UnhandledException or automatically via settings by setting CatchUnhandledExceptions to true. ```csharp using Mindscape.Raygun4Net; // Option 1: Manual hook to AppDomain var raygunClient = new RaygunClient("YOUR_APP_API_KEY"); AppDomain.CurrentDomain.UnhandledException += (sender, e) => raygunClient.Send(e.ExceptionObject as Exception); // Option 2: Auto-catch via settings var settings = new RaygunSettings { ApiKey = "YOUR_APP_API_KEY", CatchUnhandledExceptions = true }; var raygunClient = new RaygunClient(settings); ``` -------------------------------- ### Azure WebJob Exception Handling with Raygun4Net Source: https://context7.com/mindscapehq/raygun4net/llms.txt Add the Raygun4Net.Azure.WebJob package and use the `UseRaygun()` extension method on JobHostConfiguration to automatically capture exceptions. You can also pass a pre-configured RaygunClient. ```bash dotnet add package Mindscape.Raygun4Net.Azure.WebJob ``` ```csharp // WebJob Program.cs using Microsoft.Azure.WebJobs; using Mindscape.Raygun4Net; static void Main() { var config = new JobHostConfiguration(); // Attach Raygun to automatically capture WebJob exceptions config.UseRaygun(); // Or pass a pre-configured client var client = new RaygunClient("YOUR_APP_API_KEY"); client.SendingMessage += (s, e) => e.Message.Details.Tags.Add("webjob"); config.UseRaygun(client); // Add tags to all automatically-caught exceptions RaygunExceptionHandler.Tags = new[] { "azure-webjob", "production" }; var host = new JobHost(config); host.RunAndBlock(); } ``` -------------------------------- ### Send Exceptions Manually with Raygun Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.WebApi/README.md Instantiate RaygunWebApiClient and use Send or SendInBackground to report caught exceptions. ```csharp try { } catch (Exception e) { new RaygunWebApiClient().SendInBackground(e); } ``` -------------------------------- ### Raygun Settings in appsettings.json Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Define Raygun configuration settings, including the API key, within the appsettings.json file. ```json { "RaygunSettings": { "ApiKey": "YOUR_APP_API_KEY" } } ``` -------------------------------- ### Manually Send Exceptions with RaygunClient Source: https://context7.com/mindscapehq/raygun4net/llms.txt Use SendAsync for asynchronous reporting or SendInBackground for fire-and-forget background delivery. Supports adding tags and custom user data for richer context. ```csharp // ASP.NET Core: inject RaygunClient via DI public class OrderController : Controller { private readonly RaygunClient _raygunClient; public OrderController(RaygunClient raygunClient) { _raygunClient = raygunClient; } [HttpPost("process")] public async Task ProcessOrder(OrderRequest request) { try { var result = await _orderService.ProcessAsync(request); return Ok(result); } catch (PaymentDeclinedException ex) { // Send with tags and custom diagnostic data await _raygunClient.SendAsync( ex, tags: new List { "payment", "order-processing" }, userCustomData: new Dictionary { { "OrderId", request.OrderId }, { "CustomerId", request.CustomerId }, { "Amount", request.Amount } } ); return StatusCode(402, "Payment declined"); } catch (Exception ex) { // Fire-and-forget background send for non-fatal errors await _raygunClient.SendInBackground(ex); return StatusCode(500); } } } // .NET Core / Console: direct client usage try { RunCriticalOperation(); } catch (Exception ex) { await raygunClient.SendAsync( ex, tags: new List { "background-job", "critical" }, userCustomData: new Dictionary { { "JobId", jobId } } ); } ``` -------------------------------- ### Register Custom User Provider in Services Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Register your custom user provider implementation with the dependency injection container. ```csharp services.AddRaygunUserProvider(); ``` -------------------------------- ### Configure Proxy Credentials for RaygunClient Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Provide authentication credentials for a proxy server when sending messages to the Raygun API. Ensure the NetworkCredential is set before sending. ```csharp var raygunClient = new RaygunClient() { ProxyCredentials = new NetworkCredential("user", "password") }; ``` -------------------------------- ### Attach Raygun Client with Native iOS Crash Reporting Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Enable native iOS crash reporting by passing true for the first two boolean parameters. The first enables native error reporting, and the second hijacks native signals to solve null reference exceptions within try/catch blocks, at the cost of not reporting SIGBUS and SIGSEGV native errors. ```csharp static void Main(string[] args) { RaygunClient.Attach("YOUR_APP_API_KEY", true, true); UIApplication.Main(args, null, "AppDelegate"); } ``` -------------------------------- ### WinForms Exception Handling with RaygunClient Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Initialize RaygunClient and attach a handler to Application.ThreadException before Application.Run to send exceptions to Raygun. ```csharp private static readonly RaygunClient _raygunClient = new RaygunClient("YOUR_APP_API_KEY"); [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException); Application.Run(new Form1()); } private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { _raygunClient.Send(e.Exception); } ``` -------------------------------- ### Add RaygunSettings Section to Web.config Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Add this section to your Web.config file within the element to register Raygun settings. ```xml
``` -------------------------------- ### Configure RaygunClient for Automatic Unhandled Exception Reporting Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.NetCore/README.md Configure RaygunClient using RaygunSettings to automatically report unhandled exceptions. Set CatchUnhandledExceptions to true. ```csharp using Mindscape.Raygun4Net; private static RaygunSettings _raygunSettings = new RaygunSettings { ApiKey = "paste_your_api_key_here", CatchUnhandledExceptions = true // automatically reports any unhandled exceptions to Raygun }; private static RaygunClient _raygunClient = new RaygunClient(_raygunSettings); ``` -------------------------------- ### WPF Exception Handling with RaygunClient Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Initialize RaygunClient with your API key and attach an event handler to DispatcherUnhandledException to send exceptions to Raygun. ```csharp private RaygunClient _client = new RaygunClient("YOUR_APP_API_KEY"); public App() { DispatcherUnhandledException += OnDispatcherUnhandledException; } void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { _client.Send(e.Exception); } ``` -------------------------------- ### Programmatically Set Application Version Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Configure the application version directly within the Raygun service registration in ASP.NET Core. ```csharp services.AddRaygun(settings => { settings.ApplicationVersion = "1.0.0.0"; }); ``` -------------------------------- ### Configure Raygun Logging in ASP.NET Core Source: https://context7.com/mindscapehq/raygun4net/llms.txt Integrate Raygun logging into an ASP.NET Core application by adding services and configuring the Raygun logger options, such as minimum log level and whether to only log exceptions. ```csharp // Program.cs — ASP.NET Core using Mindscape.Raygun4Net.AspNetCore; using Mindscape.Raygun4Net.Extensions.Logging; var builder = WebApplication.CreateBuilder(args); builder.Services.AddRaygun(settings => { settings.ApiKey = "YOUR_APP_API_KEY"; }); builder.Services.AddRaygunUserProvider(); builder.Logging.AddRaygunLogger(options => { options.MinimumLogLevel = LogLevel.Error; // only Error and above options.OnlyLogExceptions = true; // skip logs without exceptions }); var app = builder.Build(); ``` -------------------------------- ### Configure Raygun Logger in .NET Core Service Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.Extensions.Logging/README.md Register the Raygun Client and Logger provider in a .NET Core service application's Program.cs. The API key is required for options. The Raygun Logger is then registered for use with the MS Logger. ```csharp using Mindscape.Raygun4Net.Extensions.Logging; using Mindscape.Raygun4Net.NetCore; var builder = Host.CreateApplicationBuilder(args); // Registers the Raygun Client for NetCore builder.Services.AddRaygun(options => { options.ApiKey = "*your api key*"; }); // Registers the Raygun Logger for use in MS Logger builder.Logging.AddRaygunLogger(); var host = builder.Build(); ``` -------------------------------- ### Add RaygunSettings to web.config Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.Azure.WebJob/README.md Include the RaygunSettings section in your web.config file and specify your application API key. ```xml
``` -------------------------------- ### Generate Git Log for CHANGELOG.md Source: https://github.com/mindscapehq/raygun4net/blob/master/RELEASING.md Use this git command to obtain a formatted list of changes for updating the CHANGELOG.md file. ```bash git log --pretty=format:"- %s (%as)" ``` -------------------------------- ### Configure Sensitive Data Filtering in appsettings.json Source: https://context7.com/mindscapehq/raygun4net/llms.txt Use appsettings.json to define fields, query parameters, form fields, headers, and cookies that should be ignored by Raygun. Wildcards can be used for pattern matching. ```json // appsettings.json { "RaygunSettings": { "ApiKey": "YOUR_APP_API_KEY", "IgnoreSensitiveFieldNames": ["*password*", "*secret*", "*token*"], "IgnoreQueryParameterNames": ["api_key", "access_token"], "IgnoreFormFieldNames": ["*password*", "creditCardNumber"], "IgnoreHeaderNames": ["Authorization", "X-Api-Key"], "IgnoreCookieNames": ["session", "auth"], "IsRawDataIgnored": false, "UseXmlRawDataFilter": true, "UseKeyValuePairRawDataFilter": true } } ``` -------------------------------- ### Enable Raygun4Net Error Throwing Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Configure Raygun4Net to throw errors that occur within the library itself. This is useful for debugging Raygun4Net issues by allowing them to bubble up as unhandled exceptions. ```xml ``` -------------------------------- ### Add Raygun Middleware to ASP.NET Core Program.cs Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Configure the Raygun middleware in your ASP.NET Core application's Program.cs file. This enables automatic unhandled exception reporting. ```csharp using Mindscape.Raygun4Net.AspNetCore; ``` ```csharp var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRaygun(builder.Configuration); /*The rest of your builder setup*/ var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.MapGet("/throw", (Func)(() => throw new Exception("Exception in request pipeline"))); app.UseRaygun(); /*The rest of your app setup*/ ``` -------------------------------- ### Set User Information in Raygun4Net Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Set the current user's email or detailed user information for error reports. This helps in identifying the user experiencing the issue. ```csharp raygunClient.User = "user@email.com"; // OR raygunClient.UserInfo = new RaygunIdentifierMessage("user@email.com") { IsAnonymous = false, FullName = "Robbie Raygun", FirstName = "Robbie" }; ``` -------------------------------- ### Set Custom Application Version Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.Azure.WebJob/README.md Override the default assembly version reporting by setting the ApplicationVersion property on the RaygunClient. ```csharp raygunClient.ApplicationVersion = "x.x.x.x"; ``` -------------------------------- ### Send Exception with Tags and Custom Data Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Send an exception to Raygun with additional tags and custom data using the SendAsync method. ```csharp await _raygunClient.SendAsync(ex, new List { "Tag1", "Tag2" }, new Dictionary { { "customKey", "value" } }); ``` -------------------------------- ### Configure Offline Crash Report Storage Source: https://context7.com/mindscapehq/raygun4net/llms.txt Set up Raygun4Net to store crash reports locally when the network is unavailable using a LocalApplicationDataCrashReportStore. Reports are retried automatically when connectivity is restored. ```csharp using Mindscape.Raygun4Net; using Mindscape.Raygun4Net.Storage; // Retry unsent reports every 30 seconds var sendStrategy = new TimerBasedSendStrategy(TimeSpan.FromSeconds(30)); // Store reports in LocalApplicationData folder var offlineStore = new LocalApplicationDataCrashReportStore(sendStrategy); var raygunClient = new RaygunClient(new RaygunSettings { ApiKey = "YOUR_APP_API_KEY", OfflineStore = offlineStore, MaxCrashReportsStoredOffline = 50 // hard limit: 64 }); // Reports are automatically stored offline when: // - Network connectivity fails // - Raygun API returns HTTP 5xx // They are retried automatically when connectivity is restored ``` -------------------------------- ### WinForms Unhandled Exception Handling with Raygun4Net Source: https://context7.com/mindscapehq/raygun4net/llms.txt Configure WinForms applications to capture unhandled exceptions using Application.ThreadException and AppDomain.CurrentDomain.UnhandledException. Initialize RaygunClient with your API key. ```csharp using Mindscape.Raygun4Net; static class Program { private static readonly RaygunClient _raygunClient = new RaygunClient("YOUR_APP_API_KEY"); [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += OnThreadException; AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; Application.Run(new MainForm()); } private static void OnThreadException(object sender, ThreadExceptionEventArgs e) => _raygunClient.Send(e.Exception); private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) => _raygunClient.Send(e.ExceptionObject as Exception); } ``` -------------------------------- ### Configure Raygun HTTP Module for IIS 7.0 Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.Mvc/README.md Add the RaygunErrorModule to the modules section in Web.config for automatic unhandled exception reporting on IIS 7.0. ```xml ``` -------------------------------- ### Set Application Version in RaygunSettings Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Override the default application version by specifying it in RaygunSettings. This can be done in appsettings.json or programmatically. ```json "RaygunSettings": { "ApplicationVersion": "1.0.0.0" } ``` -------------------------------- ### Add Custom Tags to Exceptions Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.Azure.WebJob/README.md Add custom tags to automatically tracked exceptions using the RaygunExceptionHandler class. ```csharp RaygunExceptionHandler.Tags = new[] {"CustomTag"}; ``` -------------------------------- ### Send Exception with Tags and Custom Data Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.Azure.WebJob/README.md Manually send exceptions using Send or SendInBackground overloads, providing an array of tags and a dictionary of custom data. ```csharp // Example overload for Send method (actual parameters may vary) // raygunClient.Send(exception, new[] {"tag1", "tag2"}, new Dictionary { {"key", "value"} }); ``` -------------------------------- ### Add Raygun Middleware Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Integrate Raygun exception handling into your ASP.NET Core application's middleware pipeline. This should be registered early to capture all exceptions. ```csharp public void Configure(IApplicationBuilder app, IHostingEnvironment env) { // This should be registered early in the pipeline to catch all exceptions app.UseRaygun(); } ``` -------------------------------- ### Attach Raygun to Web API Configuration Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.WebApi/README.md Call RaygunWebApiClient.Attach in your WebApiConfig.Register method to automatically send unhandled exceptions. ```csharp using Mindscape.Raygun4Net.WebApi; ``` ```csharp public static class WebApiConfig { public static void Register(HttpConfiguration config) { RaygunWebApiClient.Attach(config); // Web API routes here } } ``` -------------------------------- ### Enable Replacing Unseekable Request Streams Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Configure Raygun to replace unseekable request streams with seekable copies to ensure raw request payloads are sent with exceptions. ```json "RaygunSettings": { "ApiKey": "YOUR_APP_API_KEY", "ReplaceUnseekableRequestStreams": true } ``` -------------------------------- ### Attach Raygun Client to Xamarin iOS App Source: https://github.com/mindscapehq/raygun4net/blob/master/README.md Use this method in the main entry point to attach the Raygun client with your app API key for basic crash reporting in Xamarin iOS applications. ```csharp static void Main(string[] args) { RaygunClient.Attach("YOUR_APP_API_KEY"); UIApplication.Main(args, null, "AppDelegate"); } ``` -------------------------------- ### Configure Breadcrumb Behavior in appsettings.json Source: https://context7.com/mindscapehq/raygun4net/llms.txt Configure global breadcrumb settings such as the minimum level to record and whether to include location data. This JSON configuration affects how breadcrumbs are captured. ```json // appsettings.json — configure breadcrumb behavior { "RaygunSettings": { "ApiKey": "YOUR_APP_API_KEY", "BreadcrumbsLevel": "Info", "BreadcrumbsLocationRecordingEnabled": false } } ``` -------------------------------- ### Add Wrapper Exceptions to Raygun Client Source: https://github.com/mindscapehq/raygun4net/blob/master/Mindscape.Raygun4Net.AspNetCore/README.md Specify common outer exceptions that should be stripped to group by the inner exception instead. ```csharp _raygunClient.AddWrapperExceptions(typeof(TargetInvocationException)); ``` -------------------------------- ### Custom Error Grouping with RaygunClient Source: https://context7.com/mindscapehq/raygun4net/llms.txt Implement the CustomGroupingKey event handler to define your own logic for clustering errors in the Raygun dashboard. Leave the key null to use Raygun's default grouping. ```csharp var raygunClient = new RaygunClient("YOUR_APP_API_KEY"); raygunClient.CustomGroupingKey += (sender, eventArgs) => { var ex = eventArgs.Exception; var message = eventArgs.Message; // Group all database timeout errors together regardless of stack trace if (ex is TimeoutException && message.Details.Request?.Url?.Contains("/api/") == true) { eventArgs.CustomGroupingKey = "database-timeout-api"; return; } // Group validation errors by the first failing field if (ex is ValidationException validationEx) { // Key max length is 100 characters eventArgs.CustomGroupingKey = $"validation:{validationEx.FieldName}"; } // Leave eventArgs.CustomGroupingKey null to use Raygun's default grouping }; ``` -------------------------------- ### Record Breadcrumbs for Error Context Source: https://context7.com/mindscapehq/raygun4net/llms.txt Log a trail of events leading up to an exception to provide context in Raygun reports. Supports simple messages and detailed breadcrumbs with custom data. ```csharp using Mindscape.Raygun4Net; using Mindscape.Raygun4Net.Breadcrumbs; // Record a simple message breadcrumb RaygunClient.RecordBreadcrumb("User clicked checkout button"); // Record a detailed breadcrumb with category, level, and custom data RaygunClient.RecordBreadcrumb(new RaygunBreadcrumb { Message = "Initiating payment gateway request", Category = "payment", Level = RaygunBreadcrumbLevel.Info, CustomData = new Dictionary { { "gateway", "Stripe" }, { "amount", 49.99 }, { "currency", "USD" } } }); RaygunClient.RecordBreadcrumb("Payment gateway responded"); try { ProcessPayment(); // If this throws, breadcrumbs are included in the Raygun report } catch (Exception ex) { await raygunClient.SendAsync(ex); // The Raygun report will include the breadcrumb trail above } ``` -------------------------------- ### RaygunClient.AddWrapperExceptions Source: https://context7.com/mindscapehq/raygun4net/llms.txt Tell Raygun to unwrap specific exception types so that the meaningful inner exception is used for grouping and display. ```APIDOC ## `AddWrapperExceptions` — Strip Outer Wrapper Exceptions Tell Raygun to unwrap specific exception types so that the meaningful inner exception is used for grouping and display. ```csharp var raygunClient = new RaygunClient("YOUR_APP_API_KEY"); // Unwrap common framework wrappers // Note: TargetInvocationException and HttpUnhandledException are already unwrapped by default raygunClient.AddWrapperExceptions( typeof(AggregateException), // async Task wrappers typeof(TypeInitializationException) // static constructor failures ); // Now when an AggregateException wraps a DbException, Raygun groups by DbException try { await Task.WhenAll(task1, task2); // may throw AggregateException } catch (Exception ex) { // AggregateException is stripped; inner exceptions are reported individually await raygunClient.SendAsync(ex); } ``` ```