配置系统无法初始化app.config .NET 3.5

时间:2013-08-23 20:09:42

标签: c# wpf .net-3.5 app-config configuration-files

我有一个使用app.config的WPF应用程序。我按照中所述设置了app.config文件 Read/Write App.Config File with .NET 2.0 所以它看起来像这样:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="BDViewerLog.txt"/>
    <appendToFile value="true"/>
    <rollingStyle value="Size"/>
    <maxSizeRollBackups value="5"/>
    <maximumFileSize value="10MB"/>
    <staticLogFileName value="true"/>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %level %logger - %message%newline"/>
    </layout>
  </appender>  
<startup><supportedRuntime version="v2.0.50727" sku="Client"/></startup><system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="Service1Soap" closeTimeout="00:01:00" openTimeout="00:01:00"
          receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
          bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
        <binding name="Service1Soap1" closeTimeout="00:01:00" openTimeout="00:01:00"
          receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
          bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:9139/Service.asmx" binding="basicHttpBinding"
        bindingConfiguration="Service1Soap" contract="ServiceReferenceBDV.Service1Soap"
        name="Service1Soap" />
      <endpoint address="http://localhost:9139/Service1.asmx" binding="basicHttpBinding"
        bindingConfiguration="Service1Soap1" contract="ServiceReference1.Service1Soap"
        name="Service1Soap1" />
    </client>
  </system.serviceModel>  
    <appSettings>
      <add key="Path1" value="C:\files\Accounts.txt"/>
      <add key="PathMD5" value="C:\files\md5Accounts.txt"/>
      <add key ="LogUserActions" value="C:\files\Log.txt"/>      
    </appSettings> 

</configuration>

在c#代码中: string path = ConfigurationManager.AppSettings["Path1"];

我需要在appSettings节点中读取文件的路径,但我不断收到错误 配置系统无法初始化。我寻找类似主题的解决方案,但没有适用于我的情况。 我多次检查文件,找不到错误。 我也尝试删除\ Debug,\ Obj中的所有字段并清理和重建解决方案但没有任何效果。 我不知道还能做什么。

修正了它: 我没有在appender部分前面添加它:

  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
  </configSections>
  <log4net>
   <appender ...>
   </appender>
</log4net>

0 个答案:

没有答案
相关问题