I got the following error message when I tried to run a correctly configured and valid Enterprise Library 4.1 Logger Application Block code:
ConfigurationErrorsException
Invalid TraceListenerData type in configuration 'listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=9.9.9.9, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx"'.
The documentation recommends the following:
To prepare your application
- Set a reference to the Logging Application Block assembly:
- If you are using C#, in Visual Studio, right-click References in Solution Explorer, and then click Add References to add references to the Microsoft.Practices.EnterpriseLibrary.Logging.dll assembly, Microsoft.Practices.EnterpriseLibrary.Common.dll assembly, and Microsoft.Practices.EnterpriseLibrary.ObjectBuilder2.dll assembly.
- If you are using Visual Basic, in Visual Studio, double-click My Project, click the References tab, and then click Add Reference to select the assembly. In the list of imported namespaces at the bottom of the tab, select the following check boxes: Microsoft.Practices.EnterpriseLibrary.Logging, Microsoft.Practices.EnterpriseLibrary.Common.dll, and Microsoft.Practices.EnterpriseLibrary.ObjectBuilder2.dll.
I have referenced all the assemblies above. After a few minutes I’ve realized I must also add a reference to Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll assembly.
If you are using the DatabaseTraceListener class, you must also do the following:
- Configure the application to use the Data Access Application Block. For more information, see The Data Access Application Block.
- Execute the script named CreateLoggingDb.cmd (located in the Source\Blocks\Logging\Src\DatabaseTraceListener\Scripts folder) to create the Logging database.
Note:
It is also a good idea to add a reference to the Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll to your project so that the assembly required at run time is copied to the output folder.
So if you store your logs in the database, don’t forget to add a reference to the Logging.Database assembly as well!