Search code examples
c#.netoracleenterprise-library

Enterprise library logging Database trace listener with custom parameter input


I have log table in oracle DB and the supportting stored proc which takes following inputs and feds them to the table which have the same columns.

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

how do i fill the table using these custom parameters using enterprise libaray 5.0. I have seen many online pages but most of them suggest to create a new table and new stored procedure I even refereed the blog by Alex Oliveri here which was really helpful. But I want to use the existing table and stored procedure. Is it possible to do so or should i create a new table and stored procedure. Below is my 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


Solution

  • You will either need to create a custom trace listener that knows how to log to your table/stored procedure or modify the logging table/stored procedure to be in a format that Enterprise Library expects.

    Here is a sample database trace listener for SQL Server. It could be a good starting point for you if you decide to create a custom trace listener.

    Also, since you are using Oracle you will need to change the database script (since it is SQL Server specific). The Ultimate guide for Enterprise Library 5.0 Application Logging Block using Oracle 11g is a good blog posting about setting up database logging with Oracle.