iBener
iBener

Reputation: 540

How can I write to browser console from Blazor Server

When you use ILogger or Console.WriteLine in WebAssembly the logs are written in the browser console. But in the Blazor Server apps the logs don't appear in the browser console. I want to see the logs in the browser console (because it's very useful) while I debugging the app.

Upvotes: 0

Views: 2044

Answers (1)

Brian Parker
Brian Parker

Reputation: 14533

You can invoke the console via JsInteropt :

<button @onclick=@(()=>ConsoleLog("Hello")) >Hello</button>
@code {
    [Inject]
    public IJSRuntime JSRuntime { get; set; }

    public async void ConsoleLog(string message)
    {
        await JSRuntime.InvokeVoidAsync("console.log", message);
    }
}

Upvotes: 2

Related Questions