开发者

custom DB logging using enterprise library 4.1

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 开发者_JAVA技巧tables in Enterprise library logging block and do logging in these tables. I need to write a SP to insert values to these tables.

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.

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.

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.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜