我的工作站上运行着一个.Net webapi (Win10,IIS10),一切都很有魅力。但是,当我将它推到生产框(Win7,IIS6)时,NLog既不会写日志,也不会抛出异常。我的NLog.config在这里:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="true"
>
<targets async="true">
<target
name="logfile"
xsi:type="File"
layout="${date}|${level:uppercase=true}${message}"
fileName="C:\inetpub\wwwroot\myapp\App_Data\webapi.log"
/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logfile" />
</rules>
</nlog>无论我将fileName属性设置为什么,它都不会在Win7框上写入日志,也不会抛出异常。我会在Windows ->系统下的事件查看器中看到异常,对吗?
请注意,我没有对目标Win7框的管理访问权,但有足够的提升权限将文件写入www.root。
我遗漏了什么?一个异常或某种类型的错误将是最好的。
编辑:实际上,它在IIS 10/IIS 10上根本不工作,尽管它在Visual中运行时工作得很好(IIS Express?)。Visual和IIS管理器都以“管理员身份”运行。事件查看器中没有日志文件输出,没有异常,没有任何异常。???
发布于 2018-08-08 21:10:22
有关于NLog的https://github.com/NLog/NLog/wiki/Logging-Troubleshooting故障排除指南。
当您没有从NLog获得日志输出时,这可能是因为以下原因:
Build Action = None或Copy to Output Directory = Do not copy时,就会发生这种情况。设置Build Action = Content和"Copy to Output Directory = Copy if newer以修复此问题)还可以启用内部日志:https://github.com/NLog/NLog/wiki/Internal-logging
Update:如果您的内部日志不工作,那么就很难诊断出问题。
您可以启用抛出代码的异常:
LogManager.ThrowExceptions = true;
LogManager.ThrowConfigExceptions = true;https://stackoverflow.com/questions/51755072
复制相似问题