Closed phillip-haydon closed 12 months ago
When using Raygun with Serilog, it's not possible to use a custom client, i.e
public class CustomRaygunProvider : DefaultRaygunAspNetCoreClientProvider { private static readonly string ServiceName = Process.GetCurrentProcess().ProcessName; private static readonly string ServiceVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion ?? string.Empty; public override RaygunClient GetClient(RaygunSettings settings, HttpContext context) { var client = base.GetClient(settings, context); var email = context.User.FindFirstValue("email"); client.UserInfo = new RaygunIdentifierMessage(email) { IsAnonymous = false, Identifier = context.User.FindFirstValue("sub"), Email = email, FullName = context.User.FindFirstValue("preferred_username") }; client.ApplicationVersion = ServiceVersion; client.SendingMessage += (_, args) => { args.Message.Details.Tags ??= new List<string>(); args.Message.Details.Tags.Add(ServiceVersion); args.Message.Details.Tags.Add(ServiceName); }; return client; } }
This would be registered with asp .net core:
builder.Services.AddRaygun(builder.Configuration, new RaygunMiddlewareSettings { ClientProvider = new CustomRaygunProvider() });
This PR allows the configuration of the custom provider like so:
var key = context.Configuration["RaygunSettings:ApiKey"]; builder.Host.UseSerilog((context, configuration) => { configuration .WriteTo.Console() .WriteTo.Raygun(applicationKey: key, settings: new RaygunSettings { ApiKey = key }, raygunAspNetCoreClientProvider: new CustomRaygunProvider()); });
This allows consistency between asp .net and serilog.
When using Raygun with Serilog, it's not possible to use a custom client, i.e
This would be registered with asp .net core:
This PR allows the configuration of the custom provider like so:
This allows consistency between asp .net and serilog.