企业库5数据库记录到平面文件工作,数据库没有

时间:2013-01-24 12:00:38

标签: logging enterprise-library-5

我正在尝试将现有的Enterprise Library 5 Logging系统更改为使用数据库而不是平面文件提供程序。我已经使用配置工具生成相关的配置部分并将它们添加到我的配置文件中,但它似乎没有使用数据库,尽管平面文件仍在更新中。我的配置如下所示:

<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>

在应用程序或数据库中没有显示错误消息,但数据库为空,并且没有任何尝试连接的迹象。

1 个答案:

答案 0 :(得分:1)

如果我是诚实的,我并不完全确定我采取了什么措施来解决这个问题,但我设法达到了我从企业库中挤出错误信息的程度。事实证明,尽管我已经使用对Microsoft.Practices.EnterpriseLibrary.Logging.Database的引用编译了日志库,但我还必须向调用该库的WCF服务添加相同的引用 - 仅仅从日志系统引用它是不够的。