Hi,@William Liu. Welcome to Microsoft Q&A.
In a .NET 8 WPF Blazor hybrid application, adding a console output window directly to the WPF part of the project might not be straightforward due to the nature of the Blazor hosting model.
You could try to redirect the standard output stream to a console window in a WPF application and see if that helps.
In the App class constructor:
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
namespace YourNamespace
{
public partial class App : Application
{
[DllImport("kernel32.dll")]
private static extern bool AllocConsole();
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
// Allocating a console window
AllocConsole();
// Redirecting standard output stream to the console
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
}
}
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.