Extending Logging Help Needed

Topics: Building and extending application blocks, Data Access Application Block, General discussion, Logging Application Block
May 5, 2008 at 8:34 PM
I am fairly new to Ent. Lib. Have used the generic functions for both daab and lab. I have a requirement to only log specialize information into specific columns in the database. I had considered direct coding, but we also want the ability to e-mail and/or write to a file. These are Ent. Lib. strong suites.

I figured we would just subclass the LogEntry to add specific Extended Properties. That seems to be working fine. However, I need to reference a tracelistener and formatter to format and call the stored procedure. Here I have run into some trouble.

I am using Ent. Lib. 3.1. I have tried to copy the enterprise library's FormattedDatabaseTraceListener to create a customized listener that is writing to a Ent Lib Daab object.

The code is sound, I have compiled the configuration classes. However, I cannot get them to work in the ent. lib. manager for a separate project.

I have tried the Application Block Software Factory, but is does not deal with database tracelisteners.

Also, I have tried to use the AppBlock help throught VS 2005, but all the links point to the April release. All online help, <through search engines> have brought back only C# coding examples and all seem to reference an old "GotDotNet" site that is no longer available.

Any help here would be appreciated.

Thanks.
May 6, 2008 at 1:00 PM

There might be a much simpler way to extend database trace listener to perform
"...I have a requirement to only log specialize information into specific columns in the database..."

If the LogEntry class doesnt have the fields that you need to be logged in to your database table, You can always add these additional fields to the Extended Properties dictionary in the LogEntry class in key-value pairs. As you know, these extended properties, can be added to your formatted message, using a text formatter. Use your formatter to format these key-value pairs with necessary delimiters that will help you parse them inside a SQL Stored procedure.

Now on to SQL stored procedure WriteLog. It is only needed for you to maintain the contract ( Parameter Name, Type and data types), meaning, you are free to change the implementation of this stored procedure, to suit your needs. Now, since your formatter puts all the additional fields with delimiter of your choice, you can use the parameter @Formattedmessage inside this store procedure, parse the key-value pairs, and generate the Insert statement, that you need, to update the table with structure ( i mean columns) of your choice.

This should help you log to database with specific columns, with out creating a custom database trace listener.
May 6, 2008 at 4:19 PM


NeoAdroit wrote:

There might be a much simpler way to extend database trace listener to perform
"...I have a requirement to only log specialize information into specific columns in the database..."

If the LogEntry class doesnt have the fields that you need to be logged in to your database table, You can always add these additional fields to the Extended Properties dictionary in the LogEntry class in key-value pairs. As you know, these extended properties, can be added to your formatted message, using a text formatter. Use your formatter to format these key-value pairs with necessary delimiters that will help you parse them inside a SQL Stored procedure.

I have written a new CustomLogEntry (subclass). And yes, it adds the new fields to the extended properties.


Now on to SQL stored procedure WriteLog. It is only needed for you to maintain the contract ( Parameter Name, Type and data types), meaning, you are free to change the implementation of this stored procedure, to suit your needs. Now, since your formatter puts all the additional fields with delimiter of your choice, you can use the parameter @Formattedmessage inside this store procedure, parse the key-value pairs, and generate the Insert statement, that you need, to update the table with structure ( i mean columns) of your choice.

This should help you log to database with specific columns, with out creating a custom database trace listener.



I have created a new database trace listener to write the specialized message to the SQL. I have worked through the videos and using the enterprise library to build the designer. But I will not come up in the UI.

This sounds like a good alternative, please send me an example as I don't understand using the @Formatted message in the stored procedure. I am assuming that this is a SQL procedure call.

Thanks.
May 7, 2008 at 2:41 PM
I have created a new database trace listener to write the specialized message to the SQL. I have worked through the videos and using the enterprise library to build the designer. But I will not come up in the UI.

This could be because, you are not adding the assembly attribute in your assembly.info file for your new database trace listener project. For the EntLib Configuration console to pickup a design manager, your dll should dropped inside the same folder as the EntLib COnfiguration console exe is, and should expose an assembly attribue ConfigurationDesignManager or something of that sorts.

-This sounds like a good alternative, please send me an example as I don't understand using the @Formatted message in the stored procedure. I am assuming that this is a SQL procedure call._

I assume, you have already execute LoggingDatabase.Sql either using the CreateLoggingDb.cmd or by anyother means, this script should have created a stored procedure WriteLog in your database. It is this stored procedure that contains, all your additional values in its parameter @FormatterMessage. You need parse (break) this parameter, to get to the individual values, and create your own insert statement. Sorry I dont have a working sample at this point. The idea is, you use the existing components out of EntLib to log to a database, and just by tweaking the WriteLog stored procedure implementation , you are getting your additional columns inside your log table.

Jun 12, 2008 at 3:02 AM
I'd like to see an example of a modified WriteLog stored proc that parses the @Formatted parameter. It is an ntext parameter, and I always assumed the normal string functions in SQL server couldn't work with ntext?