Config Transforms for Raygun’s .NET Provider: Improve your workflow with Raygun and .NET

Matt Byers.NET, Web Development3 Comments

Raygun and config transform

.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.

config

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.

Purpose

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’.

Set up

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:

  1. In Visual Studio navigate to the ‘Build’ menu and select ‘Configuration Manager’:
    config transform set up step one

    Step one of setting up a config transform in Visual Studio.

  2. From the  ‘Active solution configuration’ dropdown select ‘<New…>’
  3. It is helpful to name the transform the same or similar to the environment it will be transforming (e.g. Production, Beta, Development, etc…). Settings can be copied from an existing transform if one exists: 
    config transform step two and three

    Step two and three of setting up a config transform in Visual Studio.

  4. Once the new transform has been created, it can be added to the Solution Explorer by right clicking your project’s Web.config and selecting ‘Add config transform’.
  5. Now when you click the arrow next to your Web.config you should see the newly created config transform. This will be named ‘Web.TransformName.config’.
    config transforms set up step 4 - 5

    Step four and five of setting up a config transform in Visual Studio.

Once you have a new solution configuration and config transform file, you can add a transform line like:

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.

Related articles

Running a .NET Core app in a Docker container

Are you missing out on Rayguns best features? 

Next level software intelligence across your entire stack.

3 Comments on “Config Transforms for Raygun’s .NET Provider: Improve your workflow with Raygun and .NET”

  1. Stefan Kip

    Why add a new solution configuration? Release is the one you want for deployments…
    Just add a config transform with the same name as the deployment profile and all is well…

    1. Freyja Spaven

      Hi Stefan, thanks for your comment, Matt says:

      “You are correct. It is not necessary to add a new solution configuration, but in our case we a few more deployment environments that we transform in different ways. Therefore, it is good to know how you can go about adding solution configurations for these too.”

      Hope that answered your question.
      Thanks.
      Freyja

  2. Pingback: Automatic Breadcrumb logging in Raygun4Net - how to get set up

Leave a Reply

Your email address will not be published. Required fields are marked *