gpt4 book ai didi

.net - 将 NLog 写入控制台

转载 作者:行者123 更新时间:2023-12-03 16:30:14 26 4
gpt4 key购买 nike

我对 NLog 很陌生。我有一个使用 NLog 的 .NET 框架控制台应用程序。希望配置NLog直接把日志写到控制台。我安装了 NLog 和 NLog.Config NuGet package , 在 nlog.config 中有以下内容:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<targets>
<target xsi:type="Console"
name="String"
layout="Layout"
footer="Layout"
header="Layout"
encoding="Encoding"
/>
</targets>
</nlog>
然后在 C# 中,以下两行不会打印到控制台:
var logger = LogManager.GetCurrentClassLogger();
logger.Info("hello");
在网上查了一下,但到目前为止没有找到任何东西。

最佳答案

退房 the official tutorial here .
您需要添加输出规则:

<rules>
<logger name="*" minlevel="Info" writeTo="console" />
</rules>
还可以简化您的控制台目标:
<target name="console" xsi:type="Console" />
许多有用的样本在这里: Most useful NLog configurations

关于.net - 将 NLog 写入控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50883109/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com