Loggin into Database

Feb 4, 2010 at 6:15 AM

Hi,

 

I am new to Enterprise Library, previously i was using Log4Net.

by using EL4.1 it is very easy to log to a flat file. i have been trying to log into database. but i didnt find any sample on that. can any one provide me a sample which helps me to work on Logging the log to Database.

it should cover by using the Stored Procedure, query

currently

I have added a Database Trace Listener

and given the Connection string

then used in class like this

        LogEntry entry = new LogEntry()
            {
                Message = "Hello Ent. Lib. Logging 123",
                Severity = TraceEventType.Critical
            };
            for (int i = 0; i < 100; i++)
            {
                Logger.Write(entry);
                Console.WriteLine(i);
            }

it is running fine , but i am unable to any info in DB, even i didnt mentioned any query to config file, i didnt created any table to loginfo (I looking info on  those steps )


can any one help me out on this

 

Thank You

Feb 4, 2010 at 6:36 AM

Hi,

First of all you must execute the .sql file that will create the Logging database for you. It is available in the <Drive Letter>\EntLib41Src\Blocks\Logging\Src\DatabaseTraceListener\Scripts\LoggingDatabase.sql . Then you can now (1)add a Database trace listener in the LAB. (2) Configure a connection string in your DAAB section which points to the database that was created running the said script. (3) Configure the DatabaseInstance property of the database trace listener and point it to the created connection string in step #2. (4) Add a trace listener reference to the desired category and point its reference to the database trace listener.

NOTE: If you attached the database trace listener to a new category, make sure to specify that category when calling Logger.Write(...)

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Feb 6, 2010 at 1:51 PM

hi,

 thanks for your above steps. I am logging Successfully To database.

Now I want to  categorize Exceptions on their Type Basis. how it can be possible.???

Can we Modify the Default Log Table Structure (like adding new column for Exception Type) ?

how to log new column Entry ???

Feb 8, 2010 at 2:17 AM

Yes, you can modify the table structure but you need to modify the stored procedures and create a custom database trace listener.  This also entails creating a custom log entry object which will inherit from the LogEntry class and will contain the additional information that you need to log in the modified Log table.  Here's a blog which details this approach, you can just skip the creating of the custom exception handler part if you want - http://customdatabasetracelistener.blogspot.com/2009/06/custom-dbtracelistener-w-custom.html.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Feb 8, 2010 at 9:33 AM
Edited Feb 8, 2010 at 1:54 PM

Does there any default  column  in database or Enterprise Library  property to categorize Exceptions on their Type Basis.?

Feb 9, 2010 at 7:02 AM

Hi,

There is none which comes with the default database for logging.

related thread:

http://entlib.codeplex.com/Thread/View.aspx?ThreadId=39684

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com