Logging to database using my own table

Topics: Building and extending application blocks, Logging Application Block
Nov 6, 2007 at 3:33 PM
Hi all,

I can write to the SQL table (Log) that comes with the Enterprise Library 3.1. But I really want to create my own SQL table with columns that I choose. Can this be done or are you locked into using the Log table? I have not been able to find any examples that show what I want to do. Any help would be appreciated!

Thanks,
Bob
Nov 6, 2007 at 3:54 PM
Hi Bob,

The existing DB trace listener uses that specific schema, but you're free to create your own TraceListener that writes to a different schema, either fixed or using some kind of mapping.
You can use the app block software factory for creating such a listener, or use the existing db listener as a starting point.

Hope this helps,
Fernando
Nov 6, 2007 at 4:28 PM
Hey Fernando,

Thanks for the reply. I forgot to mention that I am a newbie on this Enterprise Library 3.1 and Logging. You mentioned that I can create my own TraceListener that writes to a different schema. But how do I do this? I have scoured the documentation and seen nothing like this. You also said I could use the blocks software factory. Again, I do not know what this is. Maybe you could list for me the first 2 or 3 steps in more detail then I can take it from there.

Thanks,
Bob
Nov 6, 2007 at 6:03 PM
Hi,

There is no specific information on how to create a trace listener that writes to a different db schema, but there are topics on how to create new trace listeners (eg ms-help://ms.EntLib.2007May/EnterpriseLibrary/html/06-130-Creating_Custom_Trace_Listeners.htm).

There's also a whole section about the ABSF in ms-help://ms.EntLib.2007May/EnterpriseLibrary/html/10-000-Application_Block_Software_Factory.htm.

I suggest you look at the FormattedDatabaseTraceListener to learn how it is invoking the stored procedure, and use a similar approach to write to your tables.

Fernando
Nov 6, 2007 at 7:08 PM
Fernando,

Thanks for the links. I am completely overwhelmed by all of this. I have used the old version of the application data blocks for years and it did a great job. My problem is that I have very little time to get my client a logging solution. I do have another question: Maybe I am approaching this all wrong. My client has designed a simple log table in their sql database. They want to log various tasks. For example, they want to insert a row in this sql table when a user successfully logs on. One of the columns they want to capture is their IP address. The IP Address is not one of the columns in the Log table supplied with Enterprise Library 3.1. I would think that what I am trying to do is fairly common, no? But I cannot find a single example of this. And since I am brand new to this, I am really lost when I looked at the links you supplied. I follow these links but I do not see how to add my new IP Address column / property to the database trace listener.
Nov 6, 2007 at 7:26 PM
There is no documentation for the specific change to the db trace listener, but you can assume it's a component that gathers information and writes it to a database table. The source code is available, and you can see there's a ExecuteWriteLogStoredProcedure that sets the parameters for a stored procedure call; you'll need to replace this implementation with one that suits your needs.

Nov 8, 2007 at 3:05 PM
Send me an email an I will send you back an example of a Custom trace Listerner that writes to a custom SQL Table.

Joe
Nov 23, 2007 at 2:56 AM
Hi Bob,
Have you solved this problem? I am facing the same problem. Hope you can help me!

Thanks.
fantasyer


bh0526 wrote:
Hi all,

I can write to the SQL table (Log) that comes with the Enterprise Library 3.1. But I really want to create my own SQL table with columns that I choose. Can this be done or are you locked into using the Log table? I have not been able to find any examples that show what I want to do. Any help would be appreciated!

Thanks,
Bob