Understanding logging
Logging is an essential tool for troubleshooting any application. It helps to identify and solve problems. Logging is enabled by default in the Blazor WebAssembly project templates provided by Microsoft. However, the only logging provider that is enabled is the Console provider.
IMPORTANT NOTE
The Console provider does not store the logs, it only displays them. If you need to retain your logs, you will need to use a different provider.
The following code sample does the following:
- Injects an
ILogger<Counter>
object into the page. It uses the fully qualified name of the class type as the log category. The log category is included with each log message that is created by that instance ofILogger
. - Calls
LogInformation
to log the indicated string at theInformation
log level.
The following code writes to the log each time the button is clicked:
Counter.razor
@page "/counter"
@inject ILogger...