We keep logging simple in the application. We use Application Insights as our log sink. File logging can also be used, but you must enable that in your app service's Azure configuration.

Azure Application Insights

When we were evaluating the various places where we could store the Production logs, we had a few choices: file, database, something else. We didn't want to put it in a file, because it would not be useful. From experience, using a database to do it is not scalable. That left the third option. After careful consideration, we picked Azure Application Isights. While it does have a learning curve, you will be better off in the long run. It features powerful log analysis tools and great flexibility. Additionally, it is a very cheap solution and the free tier is quite generous. The configuration file has an entry where you can set the ApplicationInsights.InstrumentationKey. This is of course optional.

Logging in the Application

The first thing you will notice is that we actually do not log anything on any of the system pages. This was a conscious choice we made. We didn't want to pollute your logs, so we decided not to log anything. Feel free to add logging as you see fit in any of the existing pages and controllers.

Writing your own log messages could not be simpler. For a Blazor page, use @inject ILogger<PageName> Logger and use it as such: Logger.LogError("Oh no!"). Similarly, in C# code, you can inject ILogger<YourClass> into any class registered with the Dependency Injection container.

Table of Contents

An error has occurred. This application may no longer respond until reloaded. Reload 🗙