NLog配置系统初始化失败
我是 Nlog 的新手,将 Nlog 配置放在配置部分下方的 app.config 文件中,并在配置部分中定义一个部分名称,但我仍然收到此错误“配置系统无法初始化”。以下是我的 app.config 文件的内容。
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</sectionGroup>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="console" xsi:type="Console"
layout="${date:format=HH\:mm\:ss} ${level:uppercase=true} ${logger} 
${message} ${exception:format=message,type,stacktrace}"
/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="console" />
</rules>
</nlog>
</configuration>
我将 nlog 移到了sectionGroup 之外,因为它不是applicatinSettings 标记的成员。对不起我的错。
I am new to Nlog, Put the Nlog Configuration in the app.config file below the configuration section, and define a section name inside the Config Section but still I get this error "Configuration system failed to initialize". The below is the contents of my app.config file.
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</sectionGroup>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="console" xsi:type="Console"
layout="${date:format=HH\:mm\:ss} ${level:uppercase=true} ${logger}
${message} ${exception:format=message,type,stacktrace}"
/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="console" />
</rules>
</nlog>
</configuration>
I moved the nlog outside of the sectionGroup since it is not a member of the applicatinSettings tag. Sorry my fault.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是一个很好的答案,但是您是否尝试过打开 NLog 的内部日志记录?
您可以在配置文件中执行此操作,如下所示:
您也可以尝试使用单独的 NLog.config 文件,看看是否有效。这种方法(使用 NLog.config)的一个优点是,如果你能让它工作,你应该能够将 NLog.config 的内容复制到 app.config 中(如果你更愿意使用 NLog 的配置) app.config 文件中的信息而不是 NLog.config 文件中的信息)。
添加:
您的 NLog 配置中
${logger}
和${message}
之间的奇怪字符是什么?他们可能是问题的一部分吗?This is not much of an answer, but have you tried turning on NLog's internal logging?
You can do it in the config file like this:
You might also try using a separate NLog.config file and see if that works. One advantage to this approach (using NLog.config) is that if you can get it to work, you should be able to pretty much just copy the contents of the NLog.config into the app.config (if you would rather have NLog's config information in the app.config file rather than in the NLog.config file).
ADDED:
What is with the strange characters in your NLog configuration between
${logger}
and${message}
? Could they be part of the problem?我通过将以下属性添加到 Nlog.config 文件中的 NLog 标记来使其工作:
throwExceptions="false"
我还为构建转换问题包含了以下属性:
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
I got it to work by adding the following attributes to my NLog tag in the Nlog.config file:
throwExceptions="false"
I had also included the following attribute for a build transform issue:
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"