【发布时间】:2016-07-27 02:45:23
【问题描述】:
我对 NLog 有疑问。 我在文件 Nlog.config 中配置了 NLog,如下所示:
<?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"
autoReload="true"
throwExceptions="true"
internalLogLevel="Trace"
internalLogFile="d:\temp\nlog-internal.log">
<target xsi:type="File" name="log" fileName="${basedir}\logs\${date:format=dd}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
<rules>
<logger name="*" minlevel="Debug" writeTo="log" />
</rules>
</nlog>
我得到一个找不到目标日志的错误。我真的不知道我能做什么,也许有人有类似的问题。
我正在使用 .NET 4.5。
Nlog.config 位于项目的主目录中。 我在目录中设置了完全访问权限。
我尝试将配置移动到 web.config 文件中,但仍然出现错误。
2016-07-26 09:17:25.6353 Warn Skipping unknown node: target
2016-07-26 09:17:25.6353 Trace ParseRulesElement
2016-07-26 09:17:25.6623 Error Error in Parsing Configuration File. Exception: NLog.NLogConfigurationException: Exception occurred when loading configuration from D:\Project\NLog.config ---> NLog.NLogConfigurationException: Target log not found.
w NLog.Config.XmlLoggingConfiguration.ParseLoggerElement(NLogXmlElement loggerElement, IList`1 rulesCollection)
w NLog.Config.XmlLoggingConfiguration.ParseRulesElement(NLogXmlElement rulesElement, IList`1 rulesCollection)
w NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLogXmlElement nlogElement, String filePath, Boolean autoReloadDefault)
w NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLogXmlElement content, String filePath, Boolean autoReloadDefault)
w NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
项目结构:
更新(在 Michel A. 回答之后):我在 NLog.config 文件中也有属性
Build Action = Content
Copy to Output Directory = Copy always
Update2:我找到了解决方案。问题是我有反斜杠而不是正斜杠
语法错误:
fileName="${basedir}\logs\${date:format=dd}.log"
正确的语法:
fileName="${basedir}/logs/${date:format=dd}.log"
【问题讨论】:
-
检查解决方案文件夹中的 /logs/ 文件夹,并检查当前用户是否具有读/写权限(或者是否存在)。在您当前的图片中,它不是解决方案的一部分,因此这可能是一个问题。
-
我找到了解决方案。我做了一个更新。感谢您的回复:)
标签: c# asp.net asp.net-mvc nlog