ASP.NET Minimal APIs

The best way to install Raygun4Net.AspNetCore is to use use the dotnet cli tool. In your project folder run dotnet add package Mindscape.Raygun4Net.AspNetCore to install it.

Another method is to directly edit your .csproj file and add "Mindscape.Raygun4Net.AspNetCore": "6.6.6" to your dependencies. After you've done this, run dotnet.exe restore or restore packages within Visual Studio to download and install the package.

Alternatively, visit for instructions on installation.

Add the following code to your appsettings.json (if you're using another type of config, add it there):

 "RaygunSettings": {
   "ApiKey": "YOUR_APP_API_KEY"

Your app API key is displayed when you create a new application in your Raygun account, or can be viewed in the application settings. RaygunSettings has many options which are explained further down this page.

To configure the Raygun Middleware to handle exceptions that have been triggered and send unhandled exceptions automatically.

In Program.cs:

  1. Add using Mindscape.Raygun4Net.AspNetCore; to your using statements.
  2. Add builder.Services.AddRaygun(builder.Configuration);.
  3. Add app.UseRaygun(); after any other ExceptionHandling methods e.g. app.UseDeveloperExceptionPage() or app.UseExceptionHandler("/Home/Error").
using Mindscape.Raygun4Net.AspNetCore;

var builder = WebApplication.CreateBuilder(args);
/*The rest of your builder setup*/

var app = builder.Build();
/*The rest of your app setup*/

app.MapGet("/", () => "Hello World!");


The above set up will cause all unhandled exceptions to be sent to your Raygun account, where you can easily view all of your error monitoring and crash report data.

Note: To test and see unhandled errors in Raygun, you need to run your app in, Production mode (dotnet run --environment Production) That way the 'unhandled errors' are not handled by the Development exception handler.

We recommend also adding Raygun to the logging system. So when you use _logger.LogError(), it is also sent to Raygun. One of the easiest ways of doing this is to use the Serilog Raygun Sink.

Please see the main ASP.Net page to see further configuration options.

On this page: