Enterpise library 6.0 , Logging to Database .

Topics: Exception Handling Application Block, General discussion, Logging Application Block, Semantic Logging Application Block
Jun 11, 2013 at 8:54 AM
Edited Jun 11, 2013 at 9:01 AM
Hi,
we have a requirement to log the actions of the user in the Database using enterprise 6.0 .
please share us some sample application /links to start with the requirement.please also share us how to open the configuration tool in vs2012
we are using Prism .so we want to create Connection string in Bootstapper and also create Logger here.how can we do that any suggestions.
we need the config sections for enterpirse library 6.0 logging /exception handling.
also we are also need to do exception handling can you please share us some samples/links

Regards
Krishna
Jun 11, 2013 at 7:45 PM
Here's a very simple in-process database logging example(EL6 Semantic.Logging not EL6 Application Logging).

http://damienbod.wordpress.com/2013/06/07/enterprise-library-basic-semantic-logging-database/
Jun 12, 2013 at 5:11 PM
I would recommend reading the Developer’s Guide to Microsoft Enterprise Library (2nd edition) along with the code samples.

Assuming you are using XML configuration you can bootstrap the Enterprise Library configuration in a Unity bootstrapper and register the LogWriter in the container:
DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory());
LogWriterFactory logWriterFactory = new LogWriterFactory();
            
container.RegisterInstance<LogWriter>(logWriterFactory.Create());
Not sure if you are using ILoggerFacade but perhaps this thread might be interesting: http://entlib.codeplex.com/discussions/401683 .

For Prism specific information you should use the Prism Discussion Forum -- you'll definitely get better answers there. :)

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Jun 13, 2013 at 7:51 AM
Edited Jun 13, 2013 at 11:29 AM
Hi Randy,

Thanks for your reply.

after writing the below steps ,

DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory());
LogWriterFactory logWriterFactory = new LogWriterFactory();

container.RegisterInstance<LogWriter>(logWriterFactory.Create());

I get an exception
"Invalid TraceListenerData type in configuration 'listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.Form attedEventLogTraceListenerData, ".

"Invalid TraceListenerData type in configuration 'listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"'."

How to solve this


I know it is because of the Wrong entry in app.config for logging..Could I get the config for logging and exception handling if it exists already for entlib 6.0.
Jun 13, 2013 at 2:46 PM
Edited Jun 13, 2013 at 2:47 PM
I solved the error by adding the Logging.Database reference.

Another question, Can we log exception with this code or do we need an exception manager again. The reason being we also has to use exceptionhandling block and inturn use logging exceptions.let me know if you have any suggestions/ links to share with .

Regards
Krishna