EnterpriseLibrary.Logging的“loggingConfiguration”出错

时间:2011-10-11 10:11:03

标签: .net logging configuration enterprise-library enterprise-library-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

此消息logEntry.Write(log)时有1个运行时错误:

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 个答案:

答案 0 :(得分:3)

问题是您正在使用数据块(通过数据库跟踪侦听器)。这依赖于.NET Framework数据提供程序for Oracle,它是Feature Not Included in the .NET Framework Client Profile

解决方法是以.NET Framework 4为目标而不是客户端配置文件。

答案 1 :(得分:2)

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

答案 2 :(得分:2)

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

答案 3 :(得分:1)

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