dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.21k stars 9.95k forks source link

Blazor Server - ILogger is not logging to browser dev tools console #51424

Closed roysurles closed 11 months ago

roysurles commented 11 months ago

Is there an existing issue for this?

Describe the bug

Blazor Server - ILogger is not logging to browser dev tools console

Expected Behavior

ILogger in a BLazor Server app should work the same as Blazor Wasm and log to the browser dev tools console. I have only worked with Blazor Wasm in the past. Today they want to try a Blazor Server app, so shouldn't the ILogger work the same in Server as it does in Wasm?

Steps To Reproduce

1) File --> New Project --> Blazor Server (6 or 7) 2) [inject] ILogger Logger to the Counter page / component 3) Add: Logger.LogInformation("Message"); to the Counter.IncrementCount method 4) Run the app, open dev tools (I am using Edge), navigate to Counter page, click the button several times Nothing gets sent to the browser dev tools console... Even tried Console.WriteLine("Message") and nothing... this all works in Wasm

Exceptions (if any)

None

.NET Version

.Net 6 & 7

Anything else?

.Net 7 VS 17.7.5 PS C:\Users\surle> dotnet --info .NET SDK: Version: 8.0.100-rc.2.23502.2 Commit: 0abacfc2b6

Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.100-rc.2.23502.2\

.NET workloads installed: [maui-windows] Installation Source: VS 17.7.34202.233, VS 17.8.34205.153 Manifest Version: 8.0.0-rc.2.9373/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.maui\8.0.0-rc.2.9373\WorkloadManifest.json Install Type: Msi

[android] Installation Source: VS 17.7.34202.233, VS 17.8.34205.153 Manifest Version: 34.0.0-rc.2.468/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.android\34.0.0-rc.2.468\WorkloadManifest.json Install Type: Msi

[maui-maccatalyst] Installation Source: VS 17.7.34202.233 Manifest Version: 8.0.0-rc.2.9373/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.maui\8.0.0-rc.2.9373\WorkloadManifest.json Install Type: Msi

[maccatalyst] Installation Source: VS 17.7.34202.233, VS 17.8.34205.153 Manifest Version: 16.4.8968-net8-rc2/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.maccatalyst\16.4.8968-net8-rc2\WorkloadManifest.json Install Type: Msi

[maui-ios] Installation Source: VS 17.7.34202.233 Manifest Version: 8.0.0-rc.2.9373/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.maui\8.0.0-rc.2.9373\WorkloadManifest.json Install Type: Msi

[ios] Installation Source: VS 17.7.34202.233, VS 17.8.34205.153 Manifest Version: 16.4.8968-net8-rc2/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.ios\16.4.8968-net8-rc2\WorkloadManifest.json Install Type: Msi

[maui-android] Installation Source: VS 17.7.34202.233 Manifest Version: 8.0.0-rc.2.9373/8.0.100-rc.2 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100-rc.2\microsoft.net.sdk.maui\8.0.0-rc.2.9373\WorkloadManifest.json Install Type: Msi

Host: Version: 8.0.0-rc.2.23479.6 Architecture: x64 Commit: 0b25e38ad3

.NET SDKs installed: 7.0.402 [C:\Program Files\dotnet\sdk] 8.0.100-rc.1.23455.8 [C:\Program Files\dotnet\sdk] 8.0.100-rc.2.23502.2 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0-rc.1.23421.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0-rc.2.23480.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0-rc.1.23419.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0-rc.2.23479.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0-rc.1.23420.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0-rc.2.23479.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download PS C:\Users\surle>

gragra33 commented 11 months ago

@roysurles WASM & JavaScript run in the Browser, so will output to the DevTools Console. Your Server-side Blazor runs on the server, so the output will be to the Server Console, not the browser. (edit: Server-side Blazor prerenders on the server, pushes output to the browser, and handles the interactivity on the server, not the browser - see: ASP.NET Core Blazor - Server - Microsoft Learn). Look at the Server Console terminal window for your logger output.

If you want the Browser to output server-side logging, then you will need to use something like SignalR to push the server logging to the browser and custom Javascript to redirect the messages to the browser dev tools console.

javiercn commented 11 months ago

@roysurles thanks for contacting us.

@gragra33 answer is correct here, with a small clarification. You can just use JS interop if you want to send messages to the browser console from the server via console.log

gragra33 commented 11 months ago

Another option is to use 3rd-party logging like Serilog. You can just use JS interop if you want to send messages to the browser console from the server via console.log) and have a local/remote logging server for all logging from both the client and server all in one place.

ghost commented 11 months ago

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.