0

app.config を使用する WPF アプリケーションがあります。「 .NET 2.0 での App.Config ファイルの読み取り/書き込み」で説明されているように app.config ファイルを設定した ので、次のようになります。

<?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 ノードのファイルへのパスを読み取る必要がありますが、Configuration system failed to initialize というエラーが発生し続けます。同様のトピックで解決策を探しましたが、私のケースには当てはまりませんでした。ファイルを何度もチェックしましたが、エラーは見つかりませんでした。また、\Debug、\Obj からすべてのファイルを削除し、ソリューションをクリーニングして再構築しようとしましたが、何も機能しませんでした。これ以上何をすべきかわかりません。

修正: アペンダー セクションの前にこれを追加しませんでした:

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

0 に答える 0