在VS 2010 SP1下进行调试时,NLog没有写入配置的日志文件。
当我在应该写入日志文件的行中断时:
logger.Error("My Log Message");
我可以看到所有IsXyzEnabled
(特别是IsErrorEnabled)都是true
,而logger.Factory.AllTargets[0].FileName
是'C:/MyValidPath/${shortdate}.log'
。
预先创建有效路径。我没有在路径中添加任何特定权限(我知道在IIS下需要它...在VS调试中是否需要它,如果是,那么哪些权限?)。
我已配置NLog(我认为)如果出现任何问题则抛出异常,并且在执行logger.Error()
后我没有收到异常。
NLog配置文件:
<?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">
<nlog throwExceptions="true" />
<targets>
<target xsi:type="File" name="f" fileName="C:/MyValidPath/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="f" />
</rules>
</nlog>