在 asp.net core 应用程序的调试窗口中显示 NLog 输出 [英] Show NLog output in debug window of asp.net core app

查看:46
本文介绍了在 asp.net core 应用程序的调试窗口中显示 NLog 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Visual Studio 2017 调试窗口中显示 NLog(或内置调试器)正在记录的内容?

Is it possible to show what NLog (or builit-in debugger) is logging in the Visual Studio 2017 debug window?

我已将 NLog 设置为输出到文件,但对于开发而言,能够在调试窗口中查看调试消息会非常方便.我可以看到有关如何使用控制台执行此操作的文章,但对于 asp.net 项目,没有任何控制台输出,只有调试窗口.

I have NLog set to output to a file but for development it would be really handy to be able to see the debug messages in the debug window. I can see articles written on how to do this with console but for asp.net project there isn't any console output, just the debug window.

推荐答案

是的,对于 Asp.Net Core,有内置的记录器提供程序,例如 ConsoleDebug将日志写入输出窗口.

Yes, for Asp.Net Core, there are built-in logger providers like Console and Debug to write log to Output Window.

如果您使用 WebHost.CreateDefaultBuilder(args),它将使用内置提供程序 ConsoleDebug,您可以检查通过 输出窗口-> Asp.NET Core Web 服务器 输出以获得干净的结果.

If you use WebHost.CreateDefaultBuilder(args), it will uses built-in providers Console and Debug, and you could check the output by Output window-> Asp.NET Core Web Server for a clean result.

对于 ASP 入门.NET Core 2 来自 NLog,它使用下面的代码清除所有其他日志提供程序.

For Getting started with ASP.NET Core 2 from NLog, it uses code below to clear all other log providers.

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
    .UseStartup<Startup>()
    .ConfigureLogging(logging =>
    {
        logging.ClearProviders();
        logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
    })
    .UseNLog()  // NLog: setup NLog for Dependency injection
    .Build();

如果还需要登录Debug窗口,可以修改如下代码:

If you also need log in the Debug window, you could modify code like below:

        public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .ConfigureLogging(logger => {
                logger.AddNLog();
                //logger.AddConsole(); //UnComment out this line if you did not use CreateDefaultBuilder
            })
            .Build();

这篇关于在 asp.net core 应用程序的调试窗口中显示 NLog 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆