使用企业库4.1的自定义数据库日志记录 [英] custom DB logging using enterprise library 4.1

查看:75
本文介绍了使用企业库4.1的自定义数据库日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们必须创建所有已更改实体的历史日志。为此,我们已经定义了定制表。我必须将此表合并到企业库日志记录块中,并在这些表中进行日志记录。我需要写一个SP来向这些表中插入值。

We have to create a historical log of all the changed entities. we have defined our custom tables for this purpose. I have to incorporate this tables in Enterprise library logging block and do logging in these tables. I need to write a SP to insert values to these tables.

到目前为止,我从Google那里得到的是我必须创建一个继承自CustomTraceListener的侦听器并给出我的WriteMessage实现。

Till now,what i have got from google is that i have to create a listener inheriting from CustomTraceListener and give my implementation of WriteMessage.

我需要知道的是,如何将表和SP插入企业库日志记录块中。

What i need to know is,how will i plug my tables and SP in Enterprise library logging block.

推荐答案

如果您的存储过程将与以下接口一起使用:

If your stored procedure will work with the following interface:

CREATE PROCEDURE [dbo].[WriteLog]
(
    @EventID int, 
    @Priority int, 
    @Severity nvarchar(32), 
    @Title nvarchar(256), 
    @Timestamp datetime,
    @MachineName nvarchar(32), 
    @AppDomainName nvarchar(512),
    @ProcessID nvarchar(256),
    @ProcessName nvarchar(512),
    @ThreadName nvarchar(512),
    @Win32ThreadId nvarchar(128),
    @Message nvarchar(1500),
    @FormattedMessage ntext,
    @LogId int OUTPUT
)



然后,您可以直接使用数据库跟踪侦听器。只需通过配置指向您的存储过程即可。


Then you can use the Database Trace Listener out of the box. Just point to your stored procedure via configuration.

如果没有,则必须进行一些编码。您可以创建自定义跟踪侦听器,但是最简单的方法可能是复制 FormattedDatabaseTraceListener 并进行修改。 (核心实现是私有的,因此扩展并不能完全解决问题。)他们已经完成了大部分工作。唯一的更改是修改 ExecuteWriteLogStoredProcedure 以执行调用存储过程所需的操作。您还希望基于 FormattedDatabaseTraceListenerData 创建一个TraceListenerData类,并添加所需的特定配置项。

If not, then you will have to do some coding. You could create a Custom Trace Listener but the easiest way may be to copy the FormattedDatabaseTraceListener and modify. (The core implementation is private so extending doesn't get you all the way there.) They've already done most of the work. The only changes would be to modify the ExecuteWriteLogStoredProcedure to do what you need to call your stored procedure. You would also want to create a TraceListenerData class based on FormattedDatabaseTraceListenerData adding the specific configuration items that you need.

安装企业库源代码并查看 FormattedDatabaseTraceListener 类。

Install the Enterprise Library source code and take a look at the FormattedDatabaseTraceListener class.

这篇关于使用企业库4.1的自定义数据库日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆