You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 8 Blazor WebAssembly中按钮方法Console.WriteLine无输出问题

Blazor InteractiveWebAssembly中Console.WriteLine无输出的解决方法

在InteractiveWebAssembly渲染模式下,你的Blazor代码运行在浏览器的WebAssembly沙箱环境中,而非服务器端。因此Console.WriteLine("ouiii")的输出不会显示在项目启动时的终端控制台里,而是会输出到浏览器的开发者工具控制台中。

解决步骤:

  1. 打开运行项目的浏览器窗口
  2. 按下F12或Ctrl+Shift+I打开开发者工具
  3. 切换到「Console」标签页
  4. 点击计数器按钮触发IncrementCounter方法,就能看到"ouiii"的输出了

如果需要在服务器端记录日志,可以通过注入ILogger实现,示例代码如下:

private readonly ILogger<Counter> _logger;

public Counter(ILogger<Counter> logger)
{
    _logger = logger;
}

private void IncrementCounter()
{
    _logger.LogInformation("ouiii");
    counter++;
}

这种方式的日志会同时输出到服务器端控制台和浏览器开发者工具的Console标签中。

内容的提问来源于stack exchange,提问作者SoyNeko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 05:40:55