企业库日志记录数据库跟踪侦听器具有自定义参数输入

时间:2014-11-18 16:41:20

标签: c# .net oracle enterprise-library

我在oracle DB中有日志表和支持存储过程,它接受以下输入并将它们联合到具有相同列的表中。

PROCEDURE     SP_LOG_INSERT
   ( ProgramDate  Varchar2  ,
     ProgramName   date ,
     ProgramStatus varchar2,
     ProgramMessage varachar2(4000 Byte))

如何使用企业级libaray 5.0使用这些自定义参数填充表格。我见过很多在线页面,但大多数都建议创建一个新的表格和新的存储过程我甚至在Alex Oliveri here的博客上进行了评论,这真的很有帮助。但我想使用现有的表和存储过程。是可以这样做还是我应该创建一个新的表和存储过程。下面是我的TextFormatter

<formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.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>

enter image description here

1 个答案:

答案 0 :(得分:2)

您需要创建一个自定义跟踪侦听器,它知道如何登录到您的表/存储过程,或者将日志记录表/存储过程修改为Enterprise Library期望的格式。

这是SQL Server的sample database trace listener。如果您决定创建自定义跟踪侦听器,它可能是一个很好的起点。

此外,由于您使用的是Oracle,因此需要更改数据库脚本(因为它是特定于SQL Server的)。 Ultimate guide for Enterprise Library 5.0 Application Logging Block using Oracle 11g是关于使用Oracle设置数据库日志记录的好文章。