Problem with Database Logging Reference

Topics: Data Access Application Block, Logging Application Block
May 19, 2008 at 10:29 PM
Edited May 19, 2008 at 11:27 PM
I am seeing some really strange behavior (in both ent lib 3.1 and 4.0) regarding the Logging application block.  I have a library that contains a reference to the logging application block, the shared library, and the database logging application block.  This library is called from my main application which has no reference to the ent lib at all.  Upon compiling, all the necessary DLL's are copied to the bin folder EXCEPT the dll for the database logging application block.  So, I get errors whenever trying to log to the database.  I have tried adding a reference to the regular database application block (which consequently is already copied to the bin folder because it is used by another library).  This does not work.  If I manually copy the dll to the bin folder or install the database logging application block to the GAC, everything works fine.   If I add a discrete reference to the dll in my main application, everything works fine.

Does anyone have any suggestions for getting this to work?  I feel that I shouldn't have to copy the dll.  Since one of my referenced assemblies requires it, the dll should just be copied like it does on the other application blocks that I am using (data, logging, validation, etc...).  Am I missing something?  I don't even have a reference to the object builder dll (it is copied automatically).  Here is the error that I recieve

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

Here is my config

<add databaseInstanceName="removed" writeLogStoredProcName="removed"
        addCategoryStoredProcName="removed" formatter="Text Formatter"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Database Trace Listener" />

This is using VS2008 pro, and .net 3.5 (which I don't think should matter).  "Copy Local" is set to true on my library reference, and the library's reference to all the ent lib dll's.

**UPDATE:  I made a little test project with the same idea in mind.  It turns out that it will only copy the dll in question when there is actual code that references that DLL.  In this case, I don't have any code that directly references the FormattedDatabaseTraceListener class as it is created through a Factory.  Does anyone know of a clever way to handle this besides making a dummy variable or something lame like that.
May 20, 2008 at 3:51 PM
You can add a post build script in your app's project to copy the required assemblies.

Keep in mind that your library probably doesn't need a reference to logging.database to build. Because of this, this assembly reference is not added manifest of your library's assembly, so it's ignored while msbuild computes the list of files to copy. CopyLocal is an msbuild artifact that only applies to directly referenced assemblies; to copy assemblies required by the referenced assemblies the manifest is used (that's why OB's assembly is copied).

Fernando


chriscap16 wrote:
I am seeing some really strange behavior (in both ent lib 3.1 and 4.0) regarding the Logging application block.  I have a library that contains a reference to the logging application block, the shared library, and the database logging application block.  This library is called from my main application which has no reference to the ent lib at all.  Upon compiling, all the necessary DLL's are copied to the bin folder EXCEPT the dll for the database logging application block.  So, I get errors whenever trying to log to the database.  I have tried adding a reference to the regular database application block (which consequently is already copied to the bin folder because it is used by another library).  This does not work.  If I manually copy the dll to the bin folder or install the database logging application block to the GAC, everything works fine.   If I add a discrete reference to the dll in my main application, everything works fine.

Does anyone have any suggestions for getting this to work?  I feel that I shouldn't have to copy the dll.  Since one of my referenced assemblies requires it, the dll should just be copied like it does on the other application blocks that I am using (data, logging, validation, etc...).  Am I missing something?  I don't even have a reference to the object builder dll (it is copied automatically).  Here is the error that I recieve

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

Here is my config

<add databaseInstanceName="removed" writeLogStoredProcName="removed"
        addCategoryStoredProcName="removed" formatter="Text Formatter"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Database Trace Listener" />

This is using VS2008 pro, and .net 3.5 (which I don't think should matter).  "Copy Local" is set to true on my library reference, and the library's reference to all the ent lib dll's.

**UPDATE:  I made a little test project with the same idea in mind.  It turns out that it will only copy the dll in question when there is actual code that references that DLL.  In this case, I don't have any code that directly references the FormattedDatabaseTraceListener class as it is created through a Factory.  Does anyone know of a clever way to handle this besides making a dummy variable or something lame like that.



May 20, 2008 at 4:56 PM
That's a great idea.  I can't believe I didn't think of a post build event.  Is there a better way to reference the path of the Ent Lib besides a dos environment variable?
Feb 3, 2011 at 5:28 PM
Edited Feb 3, 2011 at 5:29 PM

Fernando,

I am having the same problem with

  • Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll and
  • Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll.

They are not being copied into bin and hence I get the error "Invalid TraceListenerData type in configuration". I am using visual studio 2010 Pro and Enterprise Library v5.0

Is this the only solution?

Thanks!

Feb 4, 2011 at 1:03 AM

Deploying the assembly to the GAC would probably make it work.   Otherwise, the assembly really need to be in the output folder so do either of the following :

1. make a post-build event

2. deploy the assembly manually

3. make use of a class from that assembly directly in your code

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com