Search code examples
c#asp.net-coreblazorblazor-server-side

How to turn on CircuitOptions.DetailedErrors?


I'm getting this message in the console when running a server-side Blazor app:

Error: There was an unhandled exception on the current circuit, so this circuit will be terminated. For more details turn on detailed exceptions in 'CircuitOptions.DetailedErrors'

I've had a look at the Blazor error handling documentation, but I can't work out how to actually turn on the detailed errors mentioned in that message?


Solution

  • NO CODE : EASIER & More SECURE

    Best Practice

    This is easier than most of the proposed solutions and it does not introduce a possible security issue into the code. It is also considered a coding best practice.

    Microsoft recommends adding the following to the appsettings.development.json file as it does not add code to the application that can become a security risk. It is not recommended to put this in appsettings.json as that settings file is reserved for the production environment.

    You can also use this approach to provide detailed error logging for SignalR.

    src: Handle errors in ASP.NET Core Blazor apps: Detailed circuit errors

    {
      "DetailedErrors": true, // turns on CircuitOptions.DetailedErrors
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft": "Warning",
          "Microsoft.Hosting.Lifetime": "Information",
          "Microsoft.AspNetCore.SignalR": "Debug"  // turns on SignalR debugging
        }
      }
    }