简体   繁体   中英

C# Microsoft.Practices.EnterpriseLibrary.Logging error

I am getting an error when i tried to used Microsoft.Practices.EnterpriseLibrary.Logging

The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Logging.Logger' threw an exception.

<configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="Tracing" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add fileName="F:\Service\Service\log\Full\Service.log" rollSizeKB="1024" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="None" formatter="Text Formatter" header="" footer="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="LogicalOperationStack" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" name="AppLog" />
     </listeners>
    <formatters>
      <add template="{timestamp} : {message}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="AppLog">
        <listeners>
          <add name="AppLog" />
        </listeners>
      </add>
      <add switchValue="Verbose" name="ExceptionHandling">
        <listeners>
          <add name="Exception" />
        </listeners>
      </add>
      <add switchValue="Information" name="Tracing">
        <listeners>
          <add name="Trace" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="Off" name="Logging Errors  Warnings" />
    </specialSources>
  </loggingConfiguration>

Any help will be appreciated

Thanks

k

I faced this issue and after spending long time, if found that in my configuration, declaration of "configSection" should be first tag. If there is any other tag before it then it throws same error.

In my case, there was target framework tag before my configsection. I moved it to after that and it starts working

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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