我正在使用 NLog 记录我的 asp.net mvc (C#) 应用程序中的异常。
NLog 在发布模式下不工作。在调试模式下运行时也是如此。
可能是什么问题?有什么解决办法吗?
我和你遇到了同样的问题:
- ASP.NET MVC 3
- .NET 4
- IIS 7
- 发布模式
我尝试更改目录,更改权限,但无济于事。我什至尝试启用内部日志记录,但即使这样也不起作用!没有失败,没有例外,什么都没有!
经过更多调查后,我找到了解决方案。由于某种原因,NLog 根本没有加载配置文件。在我以编程方式启用内部日志记录后,我意识到了这一点。内部日志报告了这一点:
2012-02-13 11:34:40.3181 Debug Targets for MyMvcController by level:
2012-02-13 11:34:40.3181 Debug Trace =>
2012-02-13 11:34:40.3181 Debug Debug =>
2012-02-13 11:34:40.3181 Debug Info =>
2012-02-13 11:34:40.3181 Debug Warn =>
2012-02-13 11:34:40.3181 Debug Error =>
2012-02-13 11:34:40.3181 Debug Fatal =>
这基本上是说没有为任何日志级别定义目标!绝对不正确!
我的 NLog 配置文件非常简单(并且设置为“复制到输出目录”):
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<!-- Other XML Sections -->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File" fileName="${basedir}/MyApplication.log" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="file" />
</rules>
</nlog>
</configuration>
我还是不确定why这种情况确实发生过,但是将 NLog 配置移至 web.config 中直接解决了问题。
也可以看看:https://github.com/nlog/NLog/wiki/Configuration-file#configuration-file-format https://github.com/nlog/NLog/wiki/Configuration-file#configuration-file-format
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)