【问题标题】:nlog not creating filenlog 不创建文件
【发布时间】:2017-01-23 16:17:51
【问题描述】:

根据教程,当抛出一些异常时,它会将异常写入文本文件。但就我而言,当抛出一些异常时,我无法在任何文件夹中检测到该异常文件。

我已经从 nuget 安装了 Nlog.config 并使用了

var  _logger = LogManager.GetCurrentClassLogger();

//In Controller
 _logger.Error(ex, "StringErrorMessage");

这是我的 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">
  <variable name="myvar" value="myvalue"/>
  <variable name="logDirectory" value="${basedir}/logs/${shortdate}"/>
  <targets>
    <target name="logfile" xsi:type="File" fileName="${logDirectory}/file.txt" />
  </targets>
  <rules>
    <!-- add your logging rules here -->
    <logger name="*" minlevel="Error" writeTo="logfile" />
  </rules>
</nlog>

【问题讨论】:

  • c:\temp\nlog-internal.log 中是否有任何 Nlog 错误?
  • 我有时间创建一个测试项目。使用与您共享的完全相同的配置,我可以将错误记录到文件中。确保查看 /bin/debug/logs/{date}/file.txt
  • 没有记录还是没有异常?同时检查内部日志internalLogLevel=debug
  • 同时启用throwExceptions进行调试

标签: c# xml asp.net-mvc-5 nlog


【解决方案1】:

老问题,但仍有人可能会看。

文件c:\temp\nlog-internal.log 存在吗?

如果没有,请将您的 nlog.config 文件的 Copy to Output Directory 属性设置为 Copy always

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-12
    • 1970-01-01
    相关资源
    最近更新 更多