blazorblazor-client-sideasp.net-blazor

How can I write into the browser´s console via Blazor WebAssembly?


In JavaScript we can use the following call to write debug output to the browser´s console:

console.log("My debug output.");

Output in Google Chrome:

console output in google chrome

How can I log "My debug output" in my component to the browser´s console via Blazor WebAssembly?

<button @onclick="ClickEvent">OK</button>

@code {

    private void ClickEvent()
    {
        // console.log("My debug output.");
    }
}

Solution

  • I usually do something like this:

    Console.WriteLine("My debug output.");
    

    if it's Blazor WebAssembly, I see the message in the browser´s console.

    If it's Blazor Server App I see the message in the Output window. (In the output window, there is a dropdown - select: " ASP.NET Core Web Server").