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 you 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.