【发布时间】: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