NLog配置系统初始化失败

发布于 2024-12-09 14:48:18 字数 1330 浏览 0 评论 0原文

我是 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} &#xD;&#xA;${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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

GRAY°灰色天空 2024-12-16 14:48:18

这不是一个很好的答案,但是您是否尝试过打开 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>

您也可以尝试使用单独的 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:

<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>

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?

许你一世情深 2024-12-16 14:48:18

我通过将以下属性添加到 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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文