繁体   English   中英

nlog没有创建文件

[英]nlog not creating file

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

我从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.config文件的“ Copy to Output Directory属性设置为Copy always

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM