Database logging using enterprise library 4.0

Topics: Enterprise Library Core, Exception Handling Application Block, Logging Application Block
Jun 23, 2008 at 10:10 AM
Hi,
I am trying to log the error message and the caategory.
i have added reference to 

using

Microsoft.Practices.EnterpriseLibrary.Logging

 

public

void PtoLog(string logmessage ,string logcategory)

 

 

LogEntry dblog1 = new LogEntry();

 

dblog1.Message =

"test message";

 

dblog1.Categories.Add(logcategory);

 

Logger.Write(dblog1);
 

In web config i am using a config tool for the connection string and the trace listener.
I am getting a runtime error like this,
BuildFailedException
The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, null]) failed: The value can not be null or string or empty.
Parameter name: name (Strategy type Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy, index 2)


Can any one help me out?

Thanks in advance.
Regards,
Goutham

 

Jun 23, 2008 at 3:41 PM

Hi,

Make sure the Microsoft.Practices.EnterpriseLibrary.Logging.Database assembly is deployed with your application and there's a formatter specified for the db trace listener. It shouldn't be required but the db trace listener creation fails if it isn't available.

Fernando

Jun 23, 2008 at 4:44 PM
Hi Fernando,
Thanks a lot now its working fine:-)Actually i missed out the db trace listner..But I want only the LogMessage and Log Category to be logged in the Database for my application.Coz i don't want Priority,MachineName etc for my application.Kindly lemme know the possible way.

Regards,
Goutham


fsimonazzi wrote:

Hi,

Make sure the Microsoft.Practices.EnterpriseLibrary.Logging.Database assembly is deployed with your application and there's a formatter specified for the db trace listener. It shouldn't be required but the db trace listener creation fails if it isn't available.

Fernando




Jun 23, 2008 at 5:32 PM
Edited Jun 23, 2008 at 5:33 PM
Hi,

You could change the logging stored procedure to ignore the unwanted columns, and optionally change the logging table to match, if you don't want to change the trace listener itself.

Fernando



goutham_upadhyaya wrote:
Hi Fernando,
Thanks a lot now its working fine:-)Actually i missed out the db trace listner..But I want only the LogMessage and Log Category to be logged in the Database for my application.Coz i don't want Priority,MachineName etc for my application.Kindly lemme know the possible way.

Regards,
Goutham


fsimonazzi wrote:

Hi,

Make sure the Microsoft.Practices.EnterpriseLibrary.Logging.Database assembly is deployed with your application and there's a formatter specified for the db trace listener. It shouldn't be required but the db trace listener creation fails if it isn't available.

Fernando