Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.");     } } 
like image 554
Simon Avatar asked Apr 02 '20 13:04

Simon


People also ask

How does Blazor run in the browser?

Blazor can run your client-side C# code directly in the browser, using WebAssembly. Because it's real . NET running on WebAssembly, you can re-use code and libraries from server-side parts of your application. Alternatively, Blazor can run your client logic on the server.

Should I use Blazor server or Blazor Wasm?

The Blazor Server hosting model offers several benefits: Download size is significantly smaller than a Blazor WebAssembly app, and the app loads much faster. -The app takes full advantage of server capabilities, including the use of . NET Core APIs.


1 Answers

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")

Hope this helps...

like image 158
enet Avatar answered Nov 20 '22 20:11

enet