0

I have the Blazor component library, I need to debug it. The library can be used in Blazor WASM and Blazor Server-Side Apps. For debug purposes I do some console output:

Console.WriteLine("Hello!") 

In the Blazor WASM app I can see it in the Browser Console.

Where can I see it in case of Blazor Server-Side App? Is using of the Debug.WriteLine method the only way to see the output? Is there a common way to write debug information for both Blazor WASM and Server-Side?

PS: There is no Console output in Debug window in case of Blazor Server-Side App.

Eugene Maksimov
  • 1,504
  • 17
  • 36
  • 2
    In the web app's console. The web app is still a console application so even when debugging a console window is shown. It may be hidden by other windows. Use logging if you want to control where the messages are written. – Panagiotis Kanavos Dec 21 '22 at 11:51
  • @PanagiotisKanavos If "IIS Express" is selected for debugging than the console window does not show up. https://stackoverflow.com/questions/57750887/blazor-server-side-console-writeline-not-working – maciek Dec 21 '22 at 12:11
  • @maciek which is why `Console.WriteLine` should be avoided. It's still possible to write the standard output to a file through a `web.config` setting but that's really only useful when the web app can't even start – Panagiotis Kanavos Dec 21 '22 at 12:16
  • @PanagiotisKanavos I know it should be avoided, but Eugene Maksimov still wanted to use it. – maciek Dec 21 '22 at 12:34
  • In that case the answer is to configure StdOut redirection, not the Debug Window – Panagiotis Kanavos Dec 21 '22 at 12:36

1 Answers1

1

If you are using Visual Studio on Windows, try selecting the name of the project when debugging Blazor Server App.

https://ibb.co/MpnG7qT

A console window will open and this is where your standard output is redirected. Anything you output from Console.WriteLine is shown there. What you write with Console.WriteLine is output to a standard output. In case of Linux app this would be terminal output.

maciek
  • 724
  • 2
  • 4
  • 16