Error on setting up database logging ... invalid tracelistenerdata type in configuration

Topics: Data Access Application Block, Logging Application Block
Jul 3, 2013 at 12:23 PM
This is for entlib6. Trying to initialize database logging, using static logging configuration. Get the below exception:

System.Configuration.ConfigurationErrorsException: 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"'.

Here is the config file setting being referred to (put in place by the Enterprise Library configuration editor):
        <add name="User Defined Database Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            databaseInstanceName="UserAudit" writeLogStoredProcName="WriteLog"
            addCategoryStoredProcName="AddCategory" formatter="Singe Line Test Formatter" />
Here is the constructor throwing the exception:
    static LogHelperBase()
    {
        try
        {
            //create a config source which will read the default config (redirected)
            var configurationSource = ConfigurationSourceFactory.Create();

            //initialize the static log writer
            var logWriterFactory = new LogWriterFactory(configurationSource);
            Logger.SetLogWriter(logWriterFactory.Create());

            DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory());

            //initialize the static exception handler
            var exceptionHandlerFactory = new ExceptionPolicyFactory(configurationSource);
            ExceptionPolicy.SetExceptionManager(exceptionHandlerFactory.CreateManager());            
        }
        catch (Exception ex) 
        {
            if(!EventLog.SourceExists("LogHelperBase")) EventLog.CreateEventSource("LogHelperBase","Application");
            EventLog.WriteEntry("LogHelperBase",ex.ToString(),EventLogEntryType.Error);
        }
    }
Editor
Jul 3, 2013 at 1:02 PM
Edited Jul 3, 2013 at 1:02 PM
Is Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll deployed to the output directory?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Jul 3, 2013 at 3:03 PM
This was a missing reference to that dll in a linked project. It was solved by adding the missing reference.
Marked as answer by randylevy on 10/12/2013 at 1:59 PM
Jul 10, 2013 at 12:54 PM
utekai wrote:
This was a missing reference to that dll in a linked project. It was solved by adding the missing reference.
I've found another case that is different. The reference in the project is there but it doesn't work and this exception is thrown.

A unit test project will compile and pull in this .dll to the bin/debug folder. But when the unit test is ran, for some reason this .dll (Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll) and only this one, is not pulled into the execution directory built for running the test.

This happens with both MSTest and ReSharper's test runners. Checked the 'Copy Local' setting on the reference and it's fine.

All the other enterprise library dlls are also pulled in appropriately. Just this one .dll is missing. And there are no build or deploy errors found.
Editor
Jul 10, 2013 at 1:31 PM
I've seen that happen before. See: EntLib FAQ

A post build command works or adding some sort of hard reference from that assembly in the code. E.g. private static Type dbListenerType = typeof(FormattedDatabaseTraceListener).

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Jul 15, 2013 at 2:00 PM
Edited Jul 15, 2013 at 2:04 PM
Found the issue with unit testing. When the unit test engine/runner pulled together the dlls, a couple of the enterprise logging library dlls didn't make it.

I found these attributes applied at the class level (set in the sample place as [TestClass] attribute), fixed the issue:
[DeploymentItem("Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll")]
[DeploymentItem("Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll")] 
Both of these dlls are named in such a way that the classes appear as if they could be in different dlls. For instance there is an Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll and Microsoft.Practices.EnterpriseLibrary.Logging.dll and the naming on those two are what the root cause seems to be, as the two dlls that must be pointed out as Deployment Items have extensions to those names, causing the confusion.

All the dlls here seem to be of such a size that they could be combined into just Logging and Exception handling, without needing a plethora of dlls to reference. It would make our lives easier.
Marked as answer by randylevy on 10/7/2013 at 11:10 PM
Oct 11, 2013 at 8:59 PM
randylevy wrote:
Is Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll deployed to the output directory?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
This fix worked for me. Thanks.