博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Enterprise Library 将日志记录到Oracle数据库

Posted on 2010-05-19 11:00  轩轩部落  阅读(503)  评论(0编辑  收藏  举报

在Enterprise Library企业库中没有给出将日志记录到Oracle数据库的SQL脚本,为了能够让日志记录到Oracle数据库,编写如下脚本:

spool DDD.log

prompt
prompt Creating table ORACLE_ENTLOG
prompt ============================
prompt
create table ORACLE_ENTLOG
(
  ID                 NUMBER,
  EVENTID            NUMBER,
  PRIORITY           NUMBER,
  TITLE              NVARCHAR2(500),
  MESSAGE            NVARCHAR2(1000),
  MACHINE            NVARCHAR2(100),
  TIMESTAMPS         DATE,
  SEVERITY           NVARCHAR2(100),
  APPLICATIONDOMAIN  NVARCHAR2(1000),
  PROCESSID          NVARCHAR2(256),
  PROCESSNAME        NVARCHAR2(500),
  WIN32THREADID      NVARCHAR2(128),
  THREADNAME         NVARCHAR2(500),
  EXTENDEDPROPERTIES NVARCHAR2(1000),
  CATEGORY           NVARCHAR2(1000)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 8K
    minextents 1
    maxextents unlimited
    pctincrease 50
  );

prompt
prompt Creating sequence SEQ_ENTLOG
prompt ============================
prompt
create sequence SEQ_ENTLOG
minvalue 1
maxvalue 9999999999999999999999
start with 1
increment by 1
cache 20;

prompt
prompt Creating procedure ADDCATEGORY
prompt ==============================
prompt
create or replace procedure AddCategory
(
    categoryName   in     nvarchar2,
    logID            in    number
)
as
begin
    UPDATE oracle_entlog SET Category=categoryName WHERE ID=logID;
    commit;
end;
/

prompt
prompt Creating procedure WRITELOG
prompt ===========================
prompt
CREATE OR REPLACE PROCEDURE WRITELOG
(
    LogId     out         number,
    EventId   in         number,
    Priority       in         number,
    Title         in           nvarchar2,
    Message       in         nvarchar2,
    machineName    in        nvarchar2,
    timestamp      in    Date,
    Severity        in        nvarchar2,
    AppDomainName   in         nvarchar2,
    ProcessId       in         nvarchar2,
    ProcessName      in      nvarchar2,
    Win32ThreadId    in        nvarchar2,
    ThreadName       in         nvarchar2,
    formattedmessage  in      nvarchar2

)
is
begin

    insert into oracle_entlog
    (
        ID,
        EventId,
        Priority,
        Title,
        Message,
        Machine,
        Timestamps,
        Severity,
        ApplicationDomain,
        ProcessId,
        ProcessName,
        Win32ThreadId,
        ThreadName,
        ExtendedProperties   
    )
    values
    (
        seq_entlog.Nextval,
        EventId,
        Priority,
        Title,
        Message,
        machineName,
        timestamp,
        Severity,
        AppDomainName,
        ProcessId,
        ProcessName,
        Win32ThreadId,
        ThreadName,
        formattedmessage  
        );     
        commit;   
        select seq_entlog.Currval into LogId from dual;
      
end  WriteLog;
/


spool off

 使用方法和向SqlServer插入日志一样。