我编写了以下代码:
private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();
public MyClass()
{
Console.Write("lol");
Logger.Debug("Debug test...");
Logger.Error("Debug test...");
Logger.Fatal("Debug test...");
Logger.Info("Debug test...");
Logger.Trace("Debug test...");
Logger.Warn("Debug test...");
}什么也不显示..所以我被告知将<targets>添加到配置文件中,事情是这样的..配置文件在哪里?谷歌上的任何东西,文档,或任何类似的东西都不能帮助我...
发布于 2017-02-26 16:20:44
来自NLog维基:
在执行独立*.exe应用程序时,将搜索以下位置:
因此,最简单的方法是在应用程序的目录中添加一个NLog.config文件
发布于 2017-02-26 17:46:09
或者,您也可以按照这里的https://github.com/nlog/NLog/wiki/Configuration-API博客文档中的说明,在C#中以编程方式定义配置
发布于 2019-10-08 14:48:35
供您参考的示例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"
throwConfigExceptions="true">
<targets>
<target name="logfile" xsi:type="File" fileName="file.txt" />
<target name="logconsole" xsi:type="Console" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logconsole" />
<logger name="*" minlevel="Debug" writeTo="logfile" />
</rules>
</nlog>https://stackoverflow.com/questions/42464439
复制相似问题