Blazor Server Application Global Error Handling

Cenk 951 Reputation points
2022-08-22T19:17:40.887+00:00

Hello,

I am working on a Blazor Server Application, I want to log errors into the database table and I wonder if there is a single/global catch? Can you please guide me?

Thank you.

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,372 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Willem Boeré 1 Reputation point
    2022-08-24T08:55:44.883+00:00

    Hello,

    I Would use the standard .NET ILogger.
    injecting ILogger in your components and configuring it at application startup, you can centrally manage logging via configuration in an easy way.

    You're talking about logging the errors in a database table, which is fine, but think where to log the errors in case the logging dataabase isn't there.
    Maybe make a difference between system errors (like logging database unavailable) and application errors (that are being logged in your database).

    This article describes nicely how to implement logging:
    https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-6.0

    and this article describes how to apply this in Blazor:
    https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/logging?view=aspnetcore-6.0

    Have fun,

    Cheers,

    Willem

    0 comments No comments