3

i am trying to use Common.Logging but we dont use app.config, our parameters are in several xml config files or in a database.

How can i Tell Common.Logging to get the factory Adapter from an other file?

<common>
    <logging>
      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
        <arg key="configType" value="INLINE" />
      </factoryAdapter>
    </logging>
  </common>

i need to get this config section from an other file.

any sugestion?

best regrads Cajon

Cajon
  • 53
  • 1
  • 4

1 Answers1

2

You didn't specify a version of Common.Logging but I assumed and based it on 2.1.

I think you could do this by implementing Common.Logging.IConfigurationReader, something similar to what follows:

Imports System.Xml

Public Class ConfigReader
    Implements Common.Logging.IConfigurationReader

    Private _configPath As String

    Public Sub New(configPath As String)
        _configPath = configPath
    End Sub

    Public Function GetSection(sectionName As String) As Object Implements Common.Logging.IConfigurationReader.GetSection
        Dim xmlDoc As New XmlDocument()
        xmlDoc.Load(_configPath)

        Return (New Common.Logging.ConfigurationSectionHandler()).Create(Nothing, Nothing, xmlDoc.SelectSingleNode("configuration/" & sectionName))
    End Function
End Class

Then at application start you can call

Common.Logging.LogManager.Reset(New ConfigReader(pathToConfigFile))

Granted this will only work if you have one config file with all your parameters and it uses the same format as standard Common.Logging stuff. Otherwise you'll probably have to do a bunch of manually config file parsing or database calls depending on where your configuration parameters are coming from.

Dan King
  • 1,080
  • 1
  • 11
  • 28