The number of avenues and options available for building and scaling web applications is surprising, especially when I reflect on the same task that years ago would require you to build a server, find a host, and basically manage all aspects of the application.
These days you can focus on building the application while leveraging services for everything from web hosting to data analytics. A good example is Raygun.io, which handles tracking application errors and notifies you when errors occur. Let's take a closer look at what Raygun.io offers by integrating it with an existing ASP.NET application.
Error tracking in the cloud
The Raygun.io site promises a setup time of five minutes; it took approximately 20 minutes for an ASP.NET application, but that included the time needed to set up a trial account with the site. The Raygun.io service is not free; they have a rate structure depending on number of applications, errors, and so forth. However, you can take it for a spin with a 30-day free trial (no credit card needed), which is what I use in this article.
Before diving into the code, let's discuss setup on the Raygun.io side. The service organizes your logging into applications. You define an application by name and the technology being used. Figure A shows the initial screen presented when adding a new application to your Raygun.io account. You assign a name along with notification (via email) options. Figure B is presented once the Create Application button is selected. Figure C loads when the technology is selected (ASP.NET in this case).
Every Raygun.io application you create has a unique Application API Key that is used in your code for identification. The api key will appear on the screen shown in Figure C (at the top and in the step #3 area). Note, they have been removed in the examples to avoid reuse. Once you have the key value, it is time to configure the actual code to use the server. My first interaction with the Raygun.io service was in ASP.NET, so I'll show this approach.
Creating a new Raygun.io application.
Specifying the platform for your Raygun.io application.
The final setup screen provides information on using the service.
Using the service in ASP.NET
The setup steps for the client or the code side are straightforward. These steps are spelled out each time a new application is created, as shown in Figure C. While my numbers do not directly correspond to their list, the following items provide the basics of using the service.
1. Install the Raygun.io package via NuGet in your application.
2. Add ConfigSections to your App.config (or Web.config for ASP.NET) for Raygun.io settings. In addition, the RaygunSettings element with the apikey attribute is added.
3. Choose whether you will use the service via code the global Application_Error event or add the HttpModule (called RaygunErrorModule) to the application via the system.web or system.webServer elements in the configuration file.
I used the service in the previously built NancyFX example that is hosted on Microsoft Azure. Figure D shows the NuGet Package Manager with Raygun.io package located (search for raygun4net) and installed. Once installed, you will see a reference to Mindscape.Raygun4Net package in the solution. The next step is configuring the application to use Raygun.io.
Locating and installing the Raygun.io NuGet package in Visual Studio.
The following listing has the complete web.config for the ASP.NET application using Raygun.io. The three areas added to incorporate Raygun.io are in bold; this includes the addition of the RaygunSettings section, the RaygunErrorModule element within the system.webServer element, and the apikey identified in the RaygunSettings element. With the web.config changes saved, the application is now configured to use Raygun.io. This sample application is hosted on Microsoft Azure, so I publish it once packages are installed and configuration changes saved.
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="RaygunSettings" type="Mindscape.Raygun4Net.RaygunSettings, Mindscape.Raygun4Net" /> </configSections> <system.web> <compilation debug="true" targetFramework="4.5.1" /> <customErrors mode="Off" /> <httpRuntime targetFramework="4.5" /> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <httpErrors existingResponse="PassThrough" /> <handlers> <add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <remove name="OPTIONSVerbHandler" /> <remove name="TRACEVerbHandler" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> <modules> <add name="RaygunErrorModule" type="Mindscape.Raygun4Net.RaygunHttpModule" /> </modules> </system.webServer> <RaygunSettings apikey="f0f0f0f0f0f0f0f0f0f0f0f0" /> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-18.104.22.168" newVersion="22.214.171.124" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-126.96.36.199" newVersion="188.8.131.52" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
Once the application is configured, you will be notified of application errors via email (if configured), or you can visit the Raygun.io site to view application activity.
Figure E shows errors generated for this application. Notice that applications are categorized as Active, Resolved, Ignored, or Permanently Ignored. They are categorized when you drill into the individual errors as shown in Figure F; the dropdown list at the top right of the exception detail page allows you to appropriately mark it. In addition, the tabs shown at the bottom of Figure F allow you to drill into further error details, including the summary page displayed by default and Error Details, Request (details on HTTP request), and Raw Data (JSON view of the error data).
Error activity recorded for the ASP.NET application.
Individual error details along with dropdown to categorize.
Another piece of the puzzle
With all of the cloud services available today, you have everything necessary to piece together an application once you have an idea. For example, you can choose to host on AWS (Raygun.io uses it) or Heroku with MongoLab for the backend database and process/analyze errors with a service like Raygun.io.
Raygun.io is not the only option with this type of service -- other options include Airbrake and Crashlytics -- but it is one that allows you to focus on building and maintaining code without the hassle of dealing with infrastructure (beyond managing cloud services).
Tony Patton has worn many hats over his 15+ years in the IT industry while witnessing many technologies come and go. He currently focuses on .NET and Web Development while trying to grasp the many facets of supporting such technologies in a production environment on a daily basis.