1

I am trying to change an existing Enterprise Library 5 Logging system to use a Database rather than flat file provider. I have used the configuration tool to generate the relevant configuration sections and added them to my configuration file, but it does not appear to be using the database, although the flat file is still being updated. My configuration looks like this:

<configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />

    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>

 <appSettings>
    <add key="loggingenabled" value="true" />
   <connectionStrings>
    <add name="Localhost" connectionString="Database=Logging;Server=localhost;Integrated Security=SSPI"
        providerName="System.Data.SqlClient" />
  </connectionStrings>

 <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        fileName="c:\logs\Service.log" header="" footer="" formatter="Text Formatter" rollSizeKB="102400" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="None" />
      <add name="Database Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          databaseInstanceName="Localhost" writeLogStoredProcName="WriteLog"
          addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
          traceOutputOptions="DateTime, ProcessId, ThreadId" />

    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
           template="{timestamp(dd/MM/yyyy HH:mm:ss.fff)} {win32ThreadId} {category} {severity} {message}"
           name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>

          <add name="Database Trace Listener" />
          <add name="Flat File Trace 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="Database Trace Listener" />
          <add name="Flat File Trace Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>

There are no error messages showing up, in the application or database, but the database is empty and there is no sign of anything attempting to connect.

glenatron
  • 11,018
  • 13
  • 64
  • 112

1 Answers1

1

If I am honest I am not absolutely sure what I did to resolve this, but I managed to get to a point where I squeezed an error message out of Enterprise Library. It turned out that although I had compiled the logging library with references to Microsoft.Practices.EnterpriseLibrary.Logging.Database I had to also add the same reference to the WCF Service which called that library - having it referenced from the logging system alone was not sufficient.

glenatron
  • 11,018
  • 13
  • 64
  • 112