Enterprise Library 5.0 use file.config in COM interop dll

Topics: Logging Application Block
Jan 4, 2011 at 9:03 AM

I have a  problem:

Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)". Exception occurred while: while resolving. Exception is: InvalidOperationException - The type LogWriter cannot be constructed. You must configure the container to supply this value. ----------------------------------------------- At the time of the exception, the container was: Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)

I read the configuration file using the following code:

            Dim container As New UnityContainer
            Dim configurator = New UnityContainerConfigurator(container)
            ' Read the configuration files and set up the container.
            EnterpriseLibraryContainer.ConfigureContainer(configurator, New FileConfigurationSource("file.config"))
            _LogWriter = container.Resolve(Of LogWriter)()
            ' add custom listener to logWriter
            If IsLogging Then

                Dim collList As New List(Of TraceListener)
                Dim dbTraceList As TraceListener = Nothing
                Dim dblogSource As LogSource = Nothing

                dbTraceList = New SIALogListener(_connLog, _databaseLog)
                dblogSource = New LogSource("CustomDBLog", collList, SourceLevels.All)
                dblogSource.AutoFlush = True

            End If

to avoid connecting to the app or web.config file

The library works perfectly. NET but loading it from VB6 COM interop mode is evident in the error that I write.

Can you help or suggest possible solutions?
What seems strange to me is that the dll in a VS2010 function perfectly and highlights the problem only in the VB6

I attach the configuration files that load code:

<?xml version="1.0"?>
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
            <add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                fileName="SIALogging.log" formatter="Text Formatter" rollFileExistsBehavior="Increment"
                rollInterval="Day" maxArchivedFiles="30" />
            <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
                name="Text Formatter" />
            <add switchValue="All" name="General">
                    <add name="Rolling Flat File Trace Listener" />
            <allEvents switchValue="All" name="All Events" />
            <notProcessed switchValue="All" name="Unprocessed Category" />
            <errors switchValue="All" name="Logging Errors &amp; Warnings">
                    <add name="Rolling Flat File Trace Listener" />

I attach the customlistener files that load in logwriter:

 <ConfigurationElementType(GetType(CustomTraceListenerData))> _
  Public Class SIALogListener
        Inherits CustomTraceListener

        Private _conn As String
        Private _databaseLogName As String

        Public Sub New(ByVal conn As String, ByVal databaseLogName As String)
            _conn = conn
            _databaseLogName = databaseLogName
        End Sub

        Public Overrides Sub TraceData(ByVal eventCache As TraceEventCache, _
            ByVal source As String, ByVal eventType As TraceEventType, _
            ByVal id As Integer, ByVal data As Object)
        End Sub

        Public Overrides Sub Write(ByVal message As String)
            Throw New NotImplementedException
        End Sub
        Public Overrides Sub WriteLine(ByVal message As String)
            Throw New NotImplementedException
        End Sub
        Public Overrides Sub WriteLine(ByVal data As Object)
                Dim log As LogEntry = CType(data, LogEntry)
               '  my log custom
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

    End Class
End Namespace


Jan 4, 2011 at 10:02 AM

At first glance, it looks like the raised exception is because the configuration cannot be read. What I can suggest is to check http://blogs.msdn.com/b/tomholl/archive/2006/04/02/entlib2externalconfig.aspx for other approach on reading entlib external config file. Also, if you're using EntLib 5.0, you can leverage the Fluent Configuration API. HTH.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.



Jan 5, 2011 at 3:03 PM

the problem was easily solved by using "Fluent Configuration" and creating through the code  the configuration file.