1

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

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

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

4

1 回答 1

1

老实说,我不确定我做了什么来解决这个问题,但我设法从企业库中挤出了一条错误消息。事实证明,虽然我已经编译了对日志库的引用,但Microsoft.Practices.EnterpriseLibrary.Logging.Database我还必须向调用该库的 WCF 服务添加相同的引用——仅从日志系统引用它是不够的。

于 2013-01-24T16:33:02.420 回答