【问题标题】:NLog not outputing log fileNLog不输出日志文件
【发布时间】:2013-01-09 16:36:35
【问题描述】:

好的,我正在尝试在我的项目中实现 NLog,并且我已经设定了一个目标:

<target name="logfile" xsi:type="File" fileName="${basedir}/logs/${shortdate}/Report/log.txt" />

这可以工作并输出我的测试日志。但是,如果我将shortdate 更改为longdate

<target name="logfile" xsi:type="File" fileName="${basedir}/logs/${longdate}/Report/log.txt" />

或者使用${time} 属性,我没有得到任何日志。根据他们的documentationlongdatetime 应该都是有效的。我错过了什么吗?它们实际上对fileName 无效吗?

【问题讨论】:

    标签: xml nlog


    【解决方案1】:

    我怀疑 ${longdate} 会导致文件名无效(Windows 不允许使用“:”,如 /logs/01-10-2013 12:24:25.2567/Report/log.txt)。

    如果您将以下内容添加到您的 nlog.config 中

    <nlog 
        internalLogFile="c:\temp\nlogproblems.txt"  
        throwExceptions="true"  
        xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    

    您会收到有关此效果的警告

    2013-01-10 14:55:21.0436 异步处理程序 NLog.NLogRuntimeException 中的错误异常:NLog 中发生异常 ---> System.IO.FileNotFoundException:文件名、目录名或卷标语法不正确。 (HRESULT 异常:0x8007007B)

    编辑:添加文件时间示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      相关资源
      最近更新 更多