5

我有一个使用 Enterprise Library.Logging 5、.NET Framework 4.0 Client Profile 的 WPF 应用程序

我使用了数据库逻辑的日志记录。还将对 3 个 dll 的引用添加到项目中。

Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll

收到此消息时出现 1 个运行时错误logEntry.Write(log)

Invalid TraceListenerData type in configuration 'listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"'

我的 app.config 是:

<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="false">
  <listeners>
    <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      source="Enterprise Library Logging" formatter="Text Formatter"
      log="" machineName="." traceOutputOptions="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="Logging" writeLogStoredProcName="WriteLog"
      addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
      traceOutputOptions="LogicalOperationStack, DateTime, Timestamp" />
  </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: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
      name="Text Formatter" />
  </formatters>
  <logFilters>
    <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      name="Category Filter" />
  </logFilters>
  <categorySources>
    <add switchValue="All" name="Repository" />
    <add switchValue="All" autoFlush="false" name="General" />
    <add switchValue="All" name="TraceDB">
      <listeners>
        <add name="Database 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="Event Log Listener" />
      </listeners>
    </errors>
  </specialSources>
</loggingConfiguration>

我的问题是什么?

4

4 回答 4

4

问题是您正在使用数据块(通过数据库跟踪侦听器)。这依赖于 .NET Framework Data Provider for Oracle,这是.NET Framework Client Profile 中未包含的功能

解决方法是针对 .NET Framework 4 而不是客户端配置文件。

于 2011-10-12T12:43:40.370 回答
2

将目标框架更改为 .NET 4 而不是客户端配置文件解决了这个问题。所有其他论坛都说要添加对 Logging.Database 的引用,这可能仍然是必需的,但没有提到目标框架。谢谢。

于 2012-01-26T16:37:20.333 回答
2

Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll对我来说这是一个简单的错误 - 当我将它添加到我的项目时它消失了。

于 2013-10-21T19:19:16.320 回答
1

上面的答案没有解决我的问题。对我来说,我创建了一个仅用于企业库日志记录的类库项目。我为要构建的类库项目添加了所有适当的引用,但在尝试写入日志数据库时在运行时收到错误。为了解决这个问题,我不得不将 Ent Lib DLL 引用添加到 Vis Studio 中的“调用”应用程序项目,因为在运行时它显然不知道日志配置是什么。

于 2013-07-03T18:41:13.170 回答