Raygun4Aspire: (Free) lightweight Crash Reporting running locally
Posted May 6, 2024 | 3 min. (547 words)NET Aspire is a new type of project and set of NuGet packages that make it easier to coordinate the multiple moving parts of a cloud-native web application. Announced near the end of 2023, .NET Aspire is currently in Preview 6, so still a work in progress.
We’ve just released Raygun4Aspire, our Crash Reporting client for Aspire applications. This is a bit different from other Raygun clients, as it comes with a lightweight Raygun web app that runs locally, so you can view nicely presented crash reports for issues occurring in your local development environment.
This experience is entirely free forever. You have the option to provide a Raygun API Key to send exceptions encountered in your production environment to your Raygun cloud service account if you like.
Adding Raygun to the Orchestrator project
The Orchestrator project (otherwise known as AppHost) sits at the center of any Aspire application. When developing your application, it’s the Orchestrator application project that causes all the moving parts to spin up and connect together.
Install the Raygun.Aspire.Hosting.Raygun NuGet package into your AppHost project either using the package manager GUI in your IDE or use the command line. Then in Program.cs
, call AddRaygun
on the builder, after the builder is initialized and before it is used to build and run.
// The distributed application builder is created here
builder.AddRaygun();
// The builder is used to build and run the app somewhere down here
This will add the mini Raygun web app to your set of Resources, which you can open up by clicking the link in the Endpoints column. Continue with the steps to get crash reports from your other projects sending into this local Raygun site.
Capturing crash reports
In all other .NET projects in your Aspire application that you’d like to capture crash reports from, you’ll want to add the Raygun4Aspire NuGet package. Then, in Program.cs
, call AddRaygun
on the WebApplicationBuilder
, followed by calling UseRaygun
on the created application.
using Raygun4Aspire;
// The WebApplicationBuilder is created somewhere here
builder.AddRaygun();
// The builder is used to create the application a little later on
app.UseRaygun();
// Then at the end of the file, the app is commanded to run
Now, any unhandled exceptions occurring within web requests will be collected for viewing in your local Raygun site.
Sending crash reports to your Raygun account in production
If you’d like to use Raygun to view exceptions coming from your production environment, all you need to do (in addition to the above steps) is configure a Raygun application API key into the config file:
"RaygunSettings": {
"ApiKey": "paste_your_api_key_here"
}
Raygun will present you with an API key when you create a new application in your Raygun account.
Reporting exceptions from try/catch blocks
It’s highly recommended to also get visibility on exceptions that are being caught. You can do this by injecting the RaygunClient
into classes containing try/catch blocks, and then using it to send the exception:
try
{
// whatever code this function is doing
}
catch (Exception ex)
{
raygunClient.SendInBackground(ex);
}
Raygun4Aspire is packed with all the same features as Raygun4Net to customize the crash reports being logged — check out the documentation.
Not a Raygun customer yet? Try out the full Crash Reporting application free for 14 days! No credit card required.