Standart Raygun4Net library does not work well with .NET. So I've created library for new architecture:
- Built with interfaces and works via default dependency injection;
- As result, services can be easily extended or replaced;
- You can work via
IRaygunClientdirectly or useRaygunLoggeror intergrate handler into ASP.NET Core pipeline.
| Package | Description | NuGet |
|---|---|---|
| RaygunCore | Raygun client and logger | |
| RaygunCore.AspNetCore | Handler for ASP.NET Core request pipeline |
Register services in Startup class:
public void ConfigureServices(IServiceCollection services)
{
// configure with API KEY
services.AddRaygun("_API_KEY_")
.WithHttp();
// or with options
services.AddRaygun(opt => opt.ApiKey = "_API_KEY_")
.WithHttp();
// or with configuration section
services.AddRaygun(configuration)
.WithHttp();
}Method AddRaygun() registers only minimal required services. So then you can request IRaygunClient service and send errors:
public async Task<string> ActionInController([FromServices]IRaygunClient raygun)
{
try
{
// some code
}
catch (Exception ex)
{
await raygun.SendAsync(ex);
}
return "OK";
}Method WithHttp() in application services registration adds pipeline handler so any exception in request is automatically sent to Raygun.
You can register Raygun logger provider:
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging((context, logging) => logging
.AddRaygun(r => r
.Configure(opt => opt.ApiKey = "_API_KEY_")
.WithHttp()
)
);Then just use logger:
public async Task<string> ActionInController([FromServices]ILogger<MyController> logger)
{
logger.LogError(0, "My error message");
}This package has MIT license. Refer to the LICENSE for detailed information.