简体   繁体   English

配置文件中的节类型

[英]Section types in Config files

I'm using log4net for the first time, and I can't figure out how to add the appropriate config settings. 我是第一次使用log4net,我不知道如何添加适当的配置设置。 All the documentation is pretty consistent about adding a <log4net> section to the app.config file, but for it to compile correctly, don't I also need to outline my configSections ? 关于将<log4net>部分添加到app.config文件,所有文档都相当一致,但是为了使其能够正确编译,我是否还不需要概述configSections

I have the following right now: 我现在有以下几点:

<configuration>
  <configSections>
    <section name="system.serviceModel"/>
    <section name="appSettings" type="System.Configuration.ConfigurationManager"/>
    <section name="log4net"
       type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <section name="startup" />
  </configSections>
  <system.serviceModel>
   ...
  </system.serviceModel>
  <appSettings>
   ...
  </appSettings>
  <log4net>
  ...
  </log4net>
  <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>

But I'm receiving the following errors: 但是我收到以下错误:

  • XML document must contain a root level element
  • The required attribute 'type' is missing (from system.serviceModel and startup ) The required attribute 'type' is missing (来自system.serviceModelstartup
  • Could not find schema information for the element * (*=everything in log4net) Could not find schema information for the element * (* = log4net中的所有内容)

I've read a couple posts on section groups, and I've considered setting up the appSettings and log4net in a separate config file. 我已经阅读了关于部分组的appSettings文章,并且考虑过在单独的配置文件中设置appSettingslog4net This is a little over my head. 这有点让我烦恼。

Should I be using separate config files? 我应该使用单独的配置文件吗?

If I should be putting everything in one config file, how do I know what type a section is? 如果我应该将所有内容都放在一个配置文件中,我如何知道节的类型? (I'm guessing on the appSettings type based on the assembly I use to get the settings--and I got the type for log4net from the many posts including it.) (我根据用于获取设置的程序集猜测appSettings类型,而我从包括它的许多帖子中得到了log4net的类型。)

Remove the duplicate declaration in the configSections for "appSettings", "system.serviceModel", "startup" . 删除configSections"appSettings", "system.serviceModel", "startup"的重复声明。
They are already declared in the file machine.config installed by the Framework in the appropriate subfolder of C:\\WINDOWS\\Microsoft.Net 它们已经在Framework安装在C:\\ WINDOWS \\ Microsoft.Net相应子文件夹中的文件machine.config中声明。

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4Net" />
  </configSections>
  <appSettings>
     ....
  </appSettings>
  <log4net>
    <root>
       .....
    </root>
    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
       .....
    </appender>
  </log4net>
  <system.serviceModel>
      ....
  </system.serviceModel>
</configuration>

also be sure that your config file starts with <?xml version="1.0"?> 还请确保您的配置文件以<?xml version="1.0"?>开头

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM