Config Transforms for Raygun’s .NET Provider: Improve your workflow with Raygun and .NETPosted Apr 20, 2017 | 3 min. (618 words)
.NET config transforms are a convenient way of modifying the RaygunSettings object when deploying your web application across multiple environments.
In this article we’ll walk through exactly why Web.config transforms are so useful when paired with the Raygun4Net provider and how you can start using them in your .NET web application.
**What are Web.config transforms? **
Config transform files allow for the automatic transformation of a web application’s Web.config file. The Web.config file often contains settings (including Raygun’s own settings) that should be different across deployment environments. Transforms can be used to modify these settings upon deployment.
The main reason for using config transforms alongside the Raygun4Net provider is the ability to have different environments reporting to different Raygun applications. This can be achieved by having different Web.config transforms for each deployment environment.
Multiple Web.config transforms allows you to replace the RaygunSettings “apiKey” property with that of multiple Raygun applications. For example, you can have a development (or beta) environment, plus a production environment reporting to separate Raygun applications.
This is extremely beneficial for separating concerns within your development process.
Another similar use case for config transforms is having an application only send data to Raygun in certain environments but not others. This is done by setting the “apiKey” value to an empty string (“”) in the main Web.config file, then using a transform to set this value when you want to start sending data to Raygun.
Utilising this method can be helpful to reduce the number of events being sent to Raygun, especially if you have a limited number of Raygun applications and want to stop clutter from test environments.
In addition to the above benefits, config transforms can also be used to filter reported data depending on the deployment environment.
The RaygunSettings within the Web.config file has a number of options, that can also be transformed using config transforms. One very useful option is the “ignoreFormFieldNames” option. “ignoreFormFieldNames” can be used to filter out sensitive form data. Setting the “ignoreFormFieldNames” value to something like “password” will filter out all form field data with names containing “password”.
This can be very helpful for filtering sensitive data, like passwords, on a production environment but not on a development environment. (See the documentation for setting up inbound filters here.) Other useful options include: ‘ignoreHeaderNames’, ‘ignoreCookieNames’ and ‘ignoreServerVariableNames’.
Typically, the RaygunSettings section of your Web.config will look something like this:
To make use of config transforms, the value of apiKey could be set to empty (“”) and then set to the actual value via a config transform.
Setting up a Web.config transform in Visual Studio is easy:
Once you have a new solution configuration and config transform file, you can add a transform line like:
<RaygunSettings xdt:Transform="Replace" apikey="YOUR_API_KEY"/>
The above transform line will replace the empty apiKey string in your Web.config file with an actual API key. This has essentially told the Raygun4Net provider to only send events if the config transform has been applied.
Don’t forget there are various RaygunSettings options that can be similarly transformed, check them out here.
Finally, to utilize the new transform file you will need to build your application using the solution configuration you created. Doing so will apply all of the changes in your transform file to the base Web.config file. Web.config transforms can also be applied automatically using a deployment tool such as Octopus. To find out more about transforms in the Octopus deployment tool click here.
Do you have any questions about making your workflow more efficient with .NET? Get in touch with a friendly team member.