Exception after adding DatabaseTracelistener

Topics: Logging Application Block
Aug 6, 2007 at 12:21 PM
Hi All,
I am using Logging Application block of Enterprise library 3.1 when i am adding DataBase Tracelistener. It is giving Error "The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Logging.Logger' threw an exception.".
And can I add new attributes like username,status etc for the table and use .

Thanks in advance
Raj
Aug 6, 2007 at 3:08 PM
Hi,

This looks like an issue with configuration. If you're debugging you should be able to inspect the exception thrown by the type initializer. You can also enable instrumentation and look for a description of the problem in the event log.

You can modify the source code to add the new attributes, but it would be better to create a new trace listener from scratch. In any case, you'll need to update the tables and the stored procedures, as well as the trace listener class. A similar question was posted recently, you might want to look for that thread.

Regards,
Fernando
Aug 14, 2007 at 1:41 PM
Hi Fernando
Thanks for the reply. Ya It was configuration issue I was able to solve the same.
I have another query I am writing a customized trace listener for Logging.
Where I want to send information to Database. Can u help me on this .
Data base structure is different from the Enterprise library format.
If you have any information on the same will be helpfull
Regards
Rajanish
Aug 14, 2007 at 3:32 PM
Hi,

The existing Database Trace Listener is probably the best example you can get. Of course the schema would change, but other than that it should be pretty similar...

Regards,
Fernando
Aug 15, 2007 at 11:51 AM
Hi,
I am a novice to Enterprise library.
I have to write a custom Trace Listener which will take the data and will write to Database.
I couldn't find out how to change the Schema.
If you could send some snippet or link where i can find the code will be cool.

Thanks & Regards
Rajanish


Aug 15, 2007 at 2:13 PM
Hi,

There is really no "snippet" that can solve your situation. You have to define the schema for your logging tables, usually using some kind of Data Definition Language, (optionally) write stored procedures to populate these tables and finally write the .NET code that would send the information to the database, either invoking your stored procecure or executing a SQL query. This .NET code will extract the information from the LogEntry to pupulate your query's parameters. This is exactly what the DatabaseTraceListener does, and you can copy the implementation up to the point where the command to write to the database is set up but you will have to provide your implementation to set up the command to write to your tables.

Hope this helps,
Fernando