Logging block to DB configuration exception

Topics: Logging Application Block
Mar 8, 2010 at 4:55 PM

I have a VS2008 VB class library where I am "trying" to log to a database using the logging block but keep getting the exception "The configuration section for Logging cannot be found in the configuration source".  From pouring over the discussion threads, I found thread 53935 which seems to indicate that the Logging Block cannot find my app.config file.  However for the Class Library project, I have an App.config file that was created via the Enterprise Library Configuration tool and it is being copied on compile to the bin/debug directory.  I succeed when I do "Test Connection" against my LoggingConnectionString.  The contents of app.config follow.  Any ideas as to why this is happening would be greatly appreciated...

<?

<

<

<

<

</

<

xml version="1.0" encoding="utf-8"?>configuration>configSections>section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />configSections>loggingConfiguration name="Logging Application Block" tracingEnabled="true"

 

<

<

defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">listeners>add databaseInstanceName="LoggingConnectionString" writeLogStoredProcName="WriteLog"

 

addCategoryStoredProcName="AddCategory" formatter="Text Formatter"

 

listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

</

<

<

name="Database Trace Listener" />listeners>formatters>add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"

 

type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

</

<

<

<

<

</

</

</

<

<

<

<

<

</

</

<

<

<

</

</

</

</

<

<

name="Text Formatter" />formatters>categorySources>add switchValue="All" name="General">listeners>add name="Database Trace Listener" />listeners>add>categorySources>specialSources>allEvents switchValue="All" name="All Events" />notProcessed switchValue="All" name="Unprocessed Category">listeners>add name="Database Trace Listener" />listeners>notProcessed>errors switchValue="All" name="Logging Errors &amp; Warnings">listeners>add name="Database Trace Listener" />listeners>errors>specialSources>loggingConfiguration>connectionStrings>add name="LoggingConnectionString" connectionString="Data Source=(local)\SQLEXPRESS;Initial Catalog=Logging;Integrated Security=True"

 

</

<

<

<!--

<

<

<

<!--

<!--

</

</

</

<

<

</

<

<

<!--

<!--

</

</

</

providerName="System.Data.SqlClient" />connectionStrings>system.diagnostics>sources> This section defines the logging configuration for My.Application.Log -->source name="DefaultSource" switchName="DefaultSwitch">listeners>add name="FileLog" /> Uncomment the below section to write to the Application Event Log --><add name="EventLog"/>-->listeners>source>sources>switches>add name="DefaultSwitch" value="Information" />switches>sharedListeners>add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" /> Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log --><add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->sharedListeners>system.diagnostics>configuration>

Mar 8, 2010 at 11:59 PM

The config files are designed for executing assemblies only and not DLL, here.  By default, the configuration subsystem will look at  <executingassembly>.exe.config  unless you manually change it during application start-up.  You will need to merge your dll specific configuration to the executable config.

Mar 9, 2010 at 4:07 AM

Yes. I agree, your class library will be consumed by a host application (*.exe or a web app). In your host application's config file, there you should put your block config for logging.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 9, 2010 at 6:46 PM

That's was it, thank you very much for your prompt help it was greatly appreciated !