Introduction
Rollbar is used to monitor the real-time exception of our application which can be used for different environments like development, staging, and production. In this article, we are going to see how to integrate the Rollbar with our existing ASP.NET Core application.
Content
- Configuring Rollbar in ASP.NET Core application.
- Monitoring the real-time exception
Configure the Rollbar
Create or open the existing ASP.NET Core application.
Make sure your application running on ASP.NET Core 2.0+ because Rollbar V2 will not support an earlier version of .NET Core.
Install Rollbar using the below command in Package Manager Console,
Install Rollbar for ASP.NET Core.
- Install-Package Rollbar.NetCore.AspNet
Now, just go to https://rollbar.com and sign up to explore the trial version of Rollbar.
Once you are done with sign in, create a new project and go to Settings-> Project Access Token Page to get a post_server key.
Now, let’s flip into our application to configure Rollbar.
Go to Startup.cs file.
Add the below method in Startup.cs Class.
- private void ConfigureRollbarSingleton()
- {
- const string rollbarAccessToken = "[your post_Server Key]";
- const string rollbarEnvironment = "dev";
- RollbarLocator.RollbarInstance
-
- .Configure(new RollbarConfig(rollbarAccessToken) { Environment = rollbarEnvironment });
- }
From the above code provide the post server key for rollbarAccessToken.
Add the below code in ConfigureServices method.
- services.AddRollbarLogger(loggerOptions =>
- {
- loggerOptions.Filter = (loggerName, loglevel) => loglevel >= LogLevel.Trace;
- });
-
- ConfigureRollbarSingleton();
Add the rollbar middleware in configure method.
- app.UseRollbarMiddleware();
Monitoring the real time exception
Let’s run the application. I got an exception because my app is not connected with the database, now this should be logged in the Rollbar dashboard.
Now, go to the Rollbar dashboard where you can find the exception logged.
From the above figure, you can notice the stack trace of the exception.
Reference
Conclusion
We have seen how to configure and track the real-time exception in ASP.NET Core application using Rollbar which is really useful to monitor the application which is in production. Let’s see how to log the handled exception and configure the people information in my next article.