Blazor: How to log to browser console
Friday, June 18, 2021
blazor
c#
This is a very quick tutorial on how to log a message to the browser console within a Blazor component.
Add at the top of your component .razor (For example CoolButton.razor) file:
@using Microsoft.Extensions.Logging;
@inject ILogger<CoolButton> logger;
Then inside a method of your component (or where needed) just use the desired log method:
private void buttonClicked() {
logger.LogInformation("Button clicked!");
}
Keep in mind that you have different methods that you can call under logger with different usages.
Well, that's it. I just wanted to share this so hopefully it helps others and to remind myself.