Installation - NET Core
Serilog Sinks error and performance monitoring with Raygun is available using the serilog-sinks-raygun provider.
serilog-sinks-raygun is a library that you can easily add to your website or web application, which will then monitor your application and display all Serilog errors and issues affecting your users within your Raygun account. Installation is painless.
The provider is a single package (Serilog.Sinks.Raygun) which includes the sole dependency (Serilog), allowing you to drop it straight in.
Step 1 - Add packages
Install the Serilog (if not included already) and Serilog.Sinks.Raygun package into your project. You can either use the below dotnet CLI command, or the NuGet management GUI in the IDE you use.
dotnet add package Serilog
dotnet add package Serilog.Sinks.Raygun
Step 2 - Initialization
With .NET Core, it is recommended you use Dependency Injection to manage a single instance of the RaygunClient for your application and to use the Raygun Serilog Sink. The following examples assume configuration is done via appSettings.json or similar configuration files.
Example of setup for ASP.NET Applications:
using Mindscape.Raygun4Net.AspNetCore;
using Serilog;
var builder = WebApplication.CreateBuilder(args);
// Add Raygun
builder.Services.AddRaygun(builder.Configuration);
builder.Services.AddRaygunUserProvider();
builder.Host.UseSerilog((context, provider, config) =>
{
// Add the Raygun sink
config.WriteTo.Raygun(raygunClient: provider.GetRequiredService<RaygunClient>());
});
Example of setup for Console/Service:
using Mindscape.Raygun4Net;
using Serilog;
using Serilog.Sinks.Raygun.Extensions;
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
// Add Raygun
services.AddRaygun(context.Configuration);
services.AddHostedService<Worker>();
})
.UseSerilog((_, serviceProvider, config) =>
{
// Add the Raygun sink
config.WriteTo.Raygun(raygunClient: serviceProvider.GetRequiredService<RaygunClient>());
})
.Build();
await host.RunAsync();
Example of setup for MAUI:
using Serilog;
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
// Add Raygun
.AddRaygun();
var app = builder.Build();
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
// Add the Raygun sink
.WriteTo.Raygun(raygunClient: app.Services.GetRequiredService<RaygunMauiClient>())
.CreateLogger();
return app;
Step 3 - Release
Deploy Raygun into your production environment for best results, or raise a test exception. Once we detect your first error event, the Raygun app will automatically update.
Configuration properties
raygunClient
type: RaygunClientBase
required
This property is required for the Raygun Sink to function. The client can be any implementation that inherits from RaygunClientBase, this could be the Raygun4Maui client, Raygun4Net.AspNetCore client, or Raygun4Net.NetCore client. Ideally, this is resolved from the ServiceCollection in .NET Core applications.
formatProvider
type: IFormatProvider
default: null
This property supplies culture-specific formatting information. By default, it is null.
tags
type: IEnumerable<string>
default: null
This is a list of global tags that will be included on every crash report sent with this Serilog sink.
restrictedToMinimumLevel
type: LogEventLevel
default: LogEventLevel.Error
You can set the minimum log event level required in order to write an event to the sink. By default, this is set to Error as Raygun is mostly used for error reporting.
Enrich with HTTP request and response data
note:
This is only valid for .NET Standard 2.0 and above projects.
In full framework, ASP.NET applications, the HTTP request and response are available to Raygun4Net through the HttpContext.Current
accessor.
For .NET Core, this won't be available. Therefore, you'll need to add the Serilog enricher using the WithHttpDataForRaygun
method to capture the HTTP request and response data.
Raygun4Net features configured via RaygunSettings
This sink wraps the Raygun4Net provider to build a crash report from an Exception and send it to Raygun. This means all the available settings/features from RaygunSettings are available.
The provider is open source and available at the serilog-sinks-raygun public repository.