WebApi reporting custom data
mattdwen
Posted on
Jan 30 2015
Is there a way to send custom data when using the RaygunWebApiClient.Attach(config);
method with ASP.NET WebApi 2?
I'd like to override the sent user data without having to build a custom global exception handler, which doesn't look particularly elegant with WebApi.
Jason Fauchelle
Raygun
Posted on
Jan 30 2015
Hi Matt,
Currently the best way to do this is to use the Attach overload that allows you to specify a function that returns your own RaygunWebApiClient instance which you can use as follows:
RaygunWebApiClient.Attach(config, () =>
{
if (_client == null)
{
_client = new RaygunWebApiClient();
_client.SendingMessage += RaygunClient_SendingMessage;
}
return _client;
});
(Where _client is an uninitialized static RaygunWebApiClient field. Here you can see I'm attach an event handler to the SendingMessage event. This client instance will be used by the global exception handler that the Attach method sets up, and so your SendingMessage event handler will be called every time a message is about to be serialized and sent to Raygun. So, in your SendingMessage event handler, you can set the e.Message.Details.Tags property, or/and e.Message.Details.UserCustomData property to hold the custom data that you want to send.
private static void RaygunClient_SendingMessage(object sender, Mindscape.Raygun4Net.RaygunSendingMessageEventArgs e)
{
e.Message.Details.UserCustomData = ...
}
Please let me know if you have any questions about this and I'll help you out.
-Jason Fauchelle
mattdwen
Posted on
Jan 30 2015
Thanks Jason, works as advertised, cheers!