The configuration section for Logging cannot be found in the configuration source

Topics: Logging Application Block
Sep 2, 2014 at 10:41 AM
I have a class library which contains enterprise library dlls and I have my code for logging in one of the classes of this class library project, In the App.Config of this project I have specified the appropriate sections under <configSections>. Also I have specified the required tags for <loggingConfiguration>.

<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging" requirePermission="true" />
</configSections>

<loggingConfiguration name="AMSLoggingConfiguration" tracingEnabled="true" defaultCategory="General">
<listeners>
  <add name="AMS Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
      listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
      source="AMS" formatter="Text Formatter" log="Application"
      machineName="." traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack" />
</listeners>
<formatters>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"

       template="Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}
                 &#xA;Title:{title}{newline}&#xA;Severity: {severity}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
      name="Text Formatter" />
</formatters>
<categorySources>
  <add switchValue="All" name="General">
    <listeners>
      <add name="AMS Event Log Listener" />
    </listeners>
  </add>
  <add switchValue="All" name="DataAccess">
    <listeners>
      <add name="AMS Event Log Listener" />
    </listeners>
  </add>
  <add switchValue="All" name="Business">
    <listeners>
      <add name="AMS Event Log Listener" />
    </listeners>
  </add>
  <add switchValue="All" name="Service">
    <listeners>
      <add name="AMS Event Log Listener" />
    </listeners>
  </add>
</categorySources>
<specialSources>
  <allEvents switchValue="All" name="All Events" />
  <notProcessed switchValue="All" name="Unprocessed Category" />
  <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
      <add name="AMS Event Log Listener" />
    </listeners>
  </errors>
</specialSources>
</loggingConfiguration>

The reference of this class library project is being used in a web project. the issue is when my log function is called, it gives following error at Writelog function.

"The configuration section for Logging cannot be found in the configuration source."

but when set the configuration in Web.config the code is worked correctly.

Can someone provide a solution?
Sep 2, 2014 at 12:35 PM
It sounds like the configuration is not being deployed. If you are using the Logging Application Block with a web project the configuration (by default) needs to be in the web.config. So the posted configuration needs to be in web.config and not App.config.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to