StackExchange.Exceptional not logging exceptions from Blazor

478 Views Asked by At

I have a Blazor Server-Side app running with .NET 5.0 and I'm trying to switch from ElmahCore to Exceptional.
But I can't get it to log Blazor exceptions. When I throw an exception in a MVC controller it gets logged, but if I throw one in e.g. OnAfterRenderAsync nothing gets logged.

What do I need to configure to get Blazor exceptions logged with Exceptional?

Also in ElmahCore I could use ElmahExtensions.RiseError(exception); to log an exception I catched/handled in code but still wanted to show up in the error-log. Is there something similar for Exceptional?

I configured Exceptional with the default configuration from HERE.

1

There are 1 best solutions below

1
On

I downloaded the package first:

Install-Package StackExchange.Exceptional.AspNetCore -Version 2.2.17

Next, add the Exceptional tag configuration to the appsettings.json file, which contains the connection string used to store errors in the database:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "Exceptional": {
    "Store": {
      "ApplicationName": "Test",
      "Type": "SQL",
      "ConnectionString": "Your Db"
    }
  }
}

Registering AddExceptional service in ConfigureServices Method:

  services.AddExceptional(Configuration.GetSection("Exceptional"), settings =>
    {
        settings.UseExceptionalPageOnThrow = HostingEnvironment.IsDevelopment();
    });

After adding ConfigureServices next, we are going to add “UseExceptional” middleware in Configure method.

Adding app.UseExceptional(); Middleware in Configure method to handle errors:

 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {

            app.UseExceptional();
            .....
}

Then I wrote a throw exception throw new NotImplementedException();

Then you can see the record:

enter image description here

According to the article you provided, it should be done.Which side did you have a problem with?