我是第一次使用 Nlog。我的目标是只写入一个文本文件。
在 main.c 中我有
class Program
{
private static Logger logger = LogManager.GetCurrentClassLogger();
static void Main(string[] args)
{
logger.Trace("Sample trace message");
logger.Debug("Sample debug message");
logger.Info("Sample informational message");
logger.Warn("Sample warning message");
logger.Error("Sample error message");
logger.Fatal("Sample fatal error message");
}
}
我的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">
<targets>
<target name="logfile" xsi:type="File" fileName="file.txt" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile" />
</rules>
</nlog>
但我无法在当前目录中创建 txt 文件。
最佳答案
试试这个...
<targets>
<target name="logfile" xsi:type="File" fileName="${basedir}/file.txt" />
</targets>
也看看这里,introduction to NLog
.
关于c# - 如何使用 NLog 在当前目录中创建文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20198211/