NLog配置系统无法初始化

use*_*160 4 nlog

我是Nlog的新手,将Nlog配置放在配置部分下面的app.config文件中,并在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} &#xD;&#xA;${message} ${exception:format=message,type,stacktrace}"
                                                        />
    </targets>
    <rules>
      <logger name="*" minlevel="Debug" writeTo="console" />
    </rules>
  </nlog>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我将nlog移到sectionGroup之外,因为它不是applicatinSettings标记的成员.对不起我的错.

wag*_*ghe 6

这不是一个很好的答案,但你试过打开NLog的内部日志记录吗?

您可以在配置文件中执行此操作:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      internalLogLevel="Trace|Debug|Info|Warn|Error|Fatal"
      internalLogFile="NLogInternal.log"
      throwExceptions="true"
      autoReload="true">

      <!-- Rest of NLog config stuff goes here -->

</nlog>
Run Code Online (Sandbox Code Playgroud)

您也可以尝试使用单独的NLog.config文件,看看是否有效.这种方法的一个优点(使用NLog.config)是,如果你能让它工作,你应该能够将NLog.config的内容复制到app.config中(如果你想要NLog的配置) app.config文件中的信息而不是NLog.config文件中的信息.

添加:

什么是与你之间配置NLOG的奇怪的字符${logger}${message}?他们可能成为问题的一部分吗?