.net-coreasp.net-core-webapierror-loggingrollbar

Rollbar not globally handling errors at .NET Core 2.2 api project


I have set up Rollbar in my .NET Core 2.2 api project just like it described in official docs. But i can not get the middleware work. Explicitly sending error/information works fine. But when there is an unhandled exceptions in code this will not be logged by Rollbar. I have installed Rollbar and Rollbar.NetCore.AspNet packages. My Startup.cs file looks like this:

public void ConfigureServices(IServiceCollection services) {
  RollbarLocator.RollbarInstance.Configure(new RollbarConfig("MYTOKENHERE") { Environment = "ENVNAME" });

  services.AddRollbarLogger(loggerOptions =>
  {
      loggerOptions.Filter = (loggerName, loglevel) => loglevel >= LogLevel.Trace;
  });
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
  if (env.IsDevelopment())
  {
      app.UseDeveloperExceptionPage();
      app.UseDatabaseErrorPage();

      app.UseCors("MyLocalhostOrigin");
  }
  else
  {
      app.UseExceptionHandler("/Home/Error");
      app.UseHsts();
  }

  app.UseRollbarMiddleware();
}

Any idea how to get middleware part work, so that errors will be globally logged by Rollbar ?


Solution

  • Figured out that need to add CaptureUncaughtExceptions = true when configuring Rollbar.

    RollbarLocator.RollbarInstance.Configure(
       new RollbarConfig("MYTOKENHERE") 
       {
          Environment = "ENVNAME",
          CaptureUncaughtExceptions = true,
       });