Mindscape.Raygun4Net.WebApi
10.1.2
See the version list below for details.
dotnet add package Mindscape.Raygun4Net.WebApi --version 10.1.2
NuGet\Install-Package Mindscape.Raygun4Net.WebApi -Version 10.1.2
<PackageReference Include="Mindscape.Raygun4Net.WebApi" Version="10.1.2" />
paket add Mindscape.Raygun4Net.WebApi --version 10.1.2
#r "nuget: Mindscape.Raygun4Net.WebApi, 10.1.2"
// Install Mindscape.Raygun4Net.WebApi as a Cake Addin #addin nuget:?package=Mindscape.Raygun4Net.WebApi&version=10.1.2 // Install Mindscape.Raygun4Net.WebApi as a Cake Tool #tool nuget:?package=Mindscape.Raygun4Net.WebApi&version=10.1.2
Raygun4Net.WebApi - Raygun Provider for ASP .NET WebApi Framework projects
Where is my app API key?
When you create a new application on your Raygun dashboard, your app API key is displayed at the top of the instructions page. You can also find the API key by clicking the "Application Settings" button in the side bar of the Raygun dashboard.
Namespace
The main classes can be found in the Mindscape.Raygun4Net namespace.
Usage
The following instructions are for ASP.NET Framework Web API. For instructions for how to install Raygun for ASP.NET Core Web API, see the Mindscape.Raygun4Net.AspNetCore
provider here.
Install the Mindscape.Raygun4Net.WebApi NuGet 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 Mindscape.Raygun4Net.WebApi
In your Web.config file, find or add a <configSections>
element, which should be nested under the <configuration>
element, and add the following entry:
<section name="RaygunSettings" type="Mindscape.Raygun4Net.RaygunSettings, Mindscape.Raygun4Net"/>
Then reference it by adding the following line somewhere after the configSections
tag. Your app API key is displayed when you create a new application in your Raygun account, or can be viewed in the application settings. RaygunSettings
has many options which can be found here.
<RaygunSettings apikey="paste_your_api_key_here" />
Now you can either setup Raygun to send unhandled exceptions automatically or/and send exceptions manually.
To send unhandled exceptions automatically, go to your WebApiConfig
class (typically in the App_Start
directory). Call the static RaygunWebApiClient.Attach(config)
method from within the Register
method:
using Mindscape.Raygun4Net.WebApi;
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
RaygunWebApiClient.Attach(config);
// Web API routes here
}
}
If you haven't already, make sure to register the WebApiConfig
class in the Application_Start
method in your Global.asax.cs
file:
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
Anywhere in you code, you can also send exception reports manually simply by creating a new instance of the RaygunWebApiClient and call one of the Send or SendInBackground methods. This is most commonly used to send exceptions caught in a try/catch block.
try
{
}
catch (Exception e)
{
new RaygunWebApiClient().SendInBackground(e);
}
TLS Configuration
Raygun's ingestion nodes require TLS 1.1 or TLS 1.2. If you are using .NET 4.5 or earlier, you may need to enable these protocols in your application. This is done by updating the protocol property in the Application_Start
method in your Global.asax.cs
file:
protected void Application_Start()
{
// Enable TLS 1.1 and TLS 1.2 with future support for TLS 3
ServicePointManager.SecurityProtocol |= (SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls3 );
}
Providing a custom RaygunClient to the automatic exception handlers
Sometimes when setting up Raygun to send exceptions automatically, you may need to provide a custom RaygunWebApiClient instance in order to use some of the optional feature described below.
To do this, use the static RaygunWebApiClient.Attach method overload that takes a function. Within this function, return a new (or previously created) RaygunWebApiClient instance. In this function you can setup any additional options on the RaygunWebApiClient instance that you need - more information about each feature is described below.
RaygunWebApiClient.Attach(config, () => {
var client = new RaygunWebApiClient();
client.ApplicationVersion = "5.9.0.1";
client.UserInfo = new RaygunIdentifierMessage("user@example.com");
client.SendingMessage += (sender, args) =>
{
if (args.Message.Details.MachineName == "BadServer")
{
args.Cancel = true;
}
};
return client;
});
Additional configuration options and features
Exclude errors by HTTP status code
You can exclude errors by their HTTP status code by providing a comma separated list of status codes to ignore in the configuration. For example if you wanted to exclude errors that return the "I'm a teapot" response code (http://tools.ietf.org/html/rfc2324), you could use the configuration below.
<RaygunSettings apikey="YOUR_APP_API_KEY" excludeHttpStatusCodes="418" />
Exclude errors that originate from a local origin
Toggle this boolean and Raygun will not send errors to Raygun if the request originated from a local origin. i.e. A way to prevent local debug/development from notifying Raygun without having to resort to Web.config transforms.
<RaygunSettings apikey="YOUR_APP_API_KEY" excludeErrorsFromLocal="true" />
Remove sensitive request data
If you have sensitive data in an HTTP request that you wish to prevent being transmitted to Raygun, you can provide lists of possible keys (names) to remove. Keys to ignore can be specified on the RaygunSettings tag in web.config, (or you can use the equivalent methods on RaygunWebApiClient if you are setting things up in code). The available options are:
- ignoreSensitiveFieldNames
- ignoreQueryParameterNames
- ignoreFormFieldNames
- ignoreHeaderNames
- ignoreCookieNames
- ignoreServerVariableNames
These can be set to be a comma separated list of keys to ignore. Setting an option as * will indicate that all the keys will not be sent to Raygun. Placing * before, after or at both ends of a key will perform an ends-with, starts-with or contains operation respectively.
For example, ignoreFormFieldNames="password" will cause Raygun to ignore all form fields that contain "password" anywhere in the name. These options are not case sensitive.
Note: The IgnoreSensitiveFieldNames will be applied to ALL fields in the RaygunRequestMessage.
We provide extra options for removing sensitive data from the request raw data. This comes in the form of filters as implemented by the IRaygunDataFilter interface. These filters read the raw data and strip values whose keys match those found in the RaygunSettings IgnoreSensitiveFieldNames property.
We currently provide two implementations with this provider.
RaygunKeyValuePairDataFilter e.g. filtering "user=raygun&password=pewpew" RaygunXmlDataFilter e.g. filtering "<password>pewpew</password>"
These filters are initially disabled and can be enbled through the RaygunSettings class. You may also provide your own implementation of the IRaygunDataFilter and pass this to the RaygunClient to use when filtering raw data. An example for implementing an JSON filter can be found at the end of this readme.
Modify or cancel message
On a RaygunWebApiClient instance, attach an event handler to the SendingMessage event. This event handler will be called just before the RaygunWebApiClient sends an exception - either automatically or manually.
The event arguments provide the RaygunMessage object that is about to be sent. One use for this event handler is to add or modify any information on the RaygunMessage. Another use for this method is to identify exceptions that you never want to send to raygun, and if so, set e.Cancel = true to cancel the send.
Strip wrapper exceptions
If you have common outer exceptions that wrap a valuable inner exception which you'd prefer to group by, you can specify these by using the multi-parameter method:
raygunWebApiClient.AddWrapperExceptions(typeof(TargetInvocationException));
In this case, if a TargetInvocationException occurs, it will be removed and replaced with the actual InnerException that was the cause. Note that TargetInvocationException is already added to the wrapper exception list; you do not have to add this manually. This method is useful if you have your own custom wrapper exceptions, or a framework is throwing exceptions using its own wrapper.
Unique (affected) user tracking
There are properties named User and UserInfo on RaygunWebApiClient which you can set to provide user info such as ID and email address This allows you to see the count of affected users for each error in the Raygun dashboard. If you provide an email address, and the user has an associated Gravatar, you will see their avatar in the error instance page.
Make sure to abide by any privacy policies that your company follows when using this feature.
Version numbering
By default, Raygun will send the assembly version of your project with each report. If you need to provide your own custom version value, you can do so by setting the ApplicationVersion property of the RaygunWebApiClient (in the format x.x.x.x where x is a positive integer).
Tags and custom data
When sending exceptions manually, you can also send an arbitrary list of tags (an array of strings), and a collection of custom data (a dictionary of any objects). This can be done using the various Send and SendInBackground method overloads.
MVC support
Do you also need MVC Raygun support for your project? Simply install the Mindscape.Raygun4Net.Mvc NuGet package which will work happily with this WebApi package. The MVC package includes an http module that will set up an MVC exception filter which can send exceptions to Raygun that could otherwise be missed in MVC projects.
Example JSON Data Filter
using System;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Mindscape.Raygun4Net.Filters;
public class RaygunJsonDataFilter : IRaygunDataFilter
{
private const string FILTERED_VALUE = "[FILTERED]";
public bool CanParse(string data)
{
if (!string.IsNullOrEmpty(data))
{
int index = data.TakeWhile(c => char.IsWhiteSpace(c)).Count();
if (index < data.Length)
{
if (data.ElementAt(index).Equals('{'))
{
return true;
}
}
}
return false;
}
public string Filter(string data, IList<string> ignoredKeys)
{
try
{
JObject jObject = JObject.Parse(data);
FilterTokensRecursive(jObject.Children(), ignoredKeys);
return jObject.ToString(Formatting.None, null);
}
catch
{
return null;
}
}
private void FilterTokensRecursive(IEnumerable<JToken> tokens, IList<string> ignoredKeys)
{
foreach (JToken token in tokens)
{
if (token is JProperty)
{
var property = token as JProperty;
if (ShouldIgnore(property, ignoredKeys))
{
property.Value = FILTERED_VALUE;
}
else if (property.Value.Type == JTokenType.Object)
{
FilterTokensRecursive(property.Value.Children(), ignoredKeys);
}
}
}
}
private bool ShouldIgnore(JProperty property, IList<string> ignoredKeys)
{
bool hasValue = property.Value.Type != JTokenType.Null;
if (property.Value.Type == JTokenType.String)
{
hasValue = !string.IsNullOrEmpty(property.Value.ToString());
}
return hasValue && !string.IsNullOrEmpty(property.Name) && ignoredKeys.Any(f => f.Equals(property.Name, StringComparison.OrdinalIgnoreCase));
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.6.2
- Microsoft.AspNet.WebApi.Core (>= 5.1.1)
- Microsoft.CSharp (>= 4.7.0)
- Mindscape.Raygun4Net.Core (>= 10.1.2)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Mindscape.Raygun4Net.WebApi:
Package | Downloads |
---|---|
Mindscape.Raygun.log4net.WebApi
Simple log4net appender which logs to the raygun.io API from your WebApi application. |
|
log4net.Raygun.WebApi
Simple log4net appender which logs to the raygun.io API from your WebApi application. |
|
Mindscape.Raygun4Net.WebApi.Signed
Package is deprecated, please use `Mindscape.Raygun4Net.WebApi` which is signed. |
|
log4net.1.2.10.Raygun.WebApi
Simple log4net appender which logs to the raygun.io API from your WebApi application. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
11.1.2 | 74 | 11/12/2024 |
11.1.2-pre-2 | 71 | 11/12/2024 |
11.1.2-pre-1 | 103 | 9/17/2024 |
11.1.1 | 1,375 | 9/12/2024 |
11.1.0 | 601 | 8/25/2024 |
11.0.4-pre-5 | 119 | 8/23/2024 |
11.0.4-pre-4 | 115 | 8/22/2024 |
11.0.4-pre-2 | 109 | 8/15/2024 |
11.0.4-pre-1 | 109 | 8/13/2024 |
11.0.3 | 619 | 7/25/2024 |
11.0.3-pre-1 | 110 | 7/22/2024 |
11.0.2 | 729 | 6/20/2024 |
11.0.0 | 3,339 | 6/9/2024 |
11.0.0-rc1 | 98 | 6/7/2024 |
11.0.0-pre3 | 94 | 5/30/2024 |
11.0.0-pre2 | 112 | 5/24/2024 |
11.0.0-pre1 | 112 | 5/23/2024 |
10.1.2 | 2,323 | 5/9/2024 |
10.1.2-pre-1 | 116 | 5/9/2024 |
10.1.1 | 2,175 | 3/27/2024 |
10.1.1-pre-1 | 100 | 3/20/2024 |
10.1.0 | 491 | 3/18/2024 |
10.1.0-pre-2 | 102 | 3/18/2024 |
10.1.0-pre-1 | 99 | 3/15/2024 |
10.0.0 | 145 | 3/13/2024 |
10.0.0-pre-6 | 105 | 3/12/2024 |
10.0.0-pre-5 | 99 | 3/12/2024 |
10.0.0-pre-4 | 104 | 2/23/2024 |
10.0.0-pre-2 | 112 | 2/23/2024 |
10.0.0-pre-1 | 91 | 2/22/2024 |
9.0.4 | 524 | 3/3/2024 |
9.0.4-pre-1 | 2,312 | 2/29/2024 |
9.0.3 | 269 | 2/27/2024 |
9.0.2 | 184 | 2/22/2024 |
9.0.2-pre-1 | 104 | 2/19/2024 |
9.0.1 | 391 | 2/8/2024 |
9.0.0-pre3 | 104 | 2/7/2024 |
9.0.0-pre-1 | 104 | 2/2/2024 |
8.3.0-pre1 | 336 | 1/26/2024 |
8.0.0 | 17,487 | 11/14/2023 |
8.0.0-pre-1 | 113 | 11/9/2023 |
7.1.1 | 4,047 | 10/10/2023 |
7.1.0 | 279 | 10/9/2023 |
7.0.0 | 734 | 9/12/2023 |
6.0.3 | 12,761 | 6/14/2023 |
5.11.2-beta001 | 156 | 6/13/2023 |
5.11.1 | 150,244 | 2/9/2021 |
5.11.0 | 36,721 | 8/16/2020 |
5.10.3 | 23,223 | 6/29/2020 |
5.10.2 | 64,478 | 2/7/2020 |
5.10.1 | 19,008 | 12/4/2019 |
5.10.0 | 26,492 | 10/11/2019 |
5.9.0 | 21,803 | 9/16/2019 |
5.8.0 | 11,561 | 7/17/2019 |
5.7.0 | 56,798 | 4/11/2019 |
5.6.1 | 109,883 | 11/23/2018 |
5.6.0 | 41,912 | 9/17/2018 |
5.6.0-beta1 | 2,911 | 4/4/2018 |
5.5.5 | 24,951 | 7/15/2018 |
5.5.2 | 93,131 | 10/24/2017 |
5.5.0 | 41,412 | 5/16/2017 |
5.4.1 | 17,952 | 3/30/2017 |
5.3.1 | 201,922 | 6/22/2016 |
5.3.0 | 43,564 | 2/11/2016 |
5.2.0 | 18,125 | 11/24/2015 |
5.1.1 | 62,215 | 9/9/2015 |
5.1.0 | 47,216 | 6/24/2015 |
5.0.2 | 16,434 | 5/15/2015 |
5.0.1 | 8,737 | 4/16/2015 |
5.0.0 | 8,220 | 3/9/2015 |
4.2.1 | 5,455 | 2/12/2015 |
4.2.0 | 7,769 | 1/14/2015 |
4.1.0 | 6,380 | 12/5/2014 |
4.0.1 | 4,494 | 10/31/2014 |
4.0.0 | 2,893 | 10/21/2014 |