我需要翻译如下内容:
我遇到了一个错误,提示“找不到目标日志”。我真的不知道该怎么办,也许有人遇到过类似的问题。
我正在使用.NET 4.5。
Nlog.config文件位于项目的主目录中。 我已将目录权限设置为完全访问。
我尝试将配置移到web.config文件中,但错误仍然出现。
我有关于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
更新2: 我找到了解决方案。问题是我使用反斜杠而不是正斜杠。
错误的语法:
fileName="${basedir}\logs\${date:format=dd}.log"
正确的语法:
fileName="${basedir}/logs/${date:format=dd}.log"