我正在尝试使用Common.Logging,但我们没有使用app.config,我们的参数在几个xml配置文件或数据库中。
如何告诉Common.Logging从其他文件中获取工厂适配器?
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>我需要从另一个文件中获取此配置节。
有什么建议吗?
最佳回归者卡洪
发布于 2013-09-19 02:04:28
您没有指定Common.Logging的版本,但我假设它是基于2.1的。
我认为你可以通过实现Common.Logging.IConfigurationReader来做到这一点,类似于下面的内容:
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然后,在应用程序启动时,您可以调用
Common.Logging.LogManager.Reset(New ConfigReader(pathToConfigFile))当然,只有当您有一个包含所有参数的配置文件,并且它使用与标准Common.Logging内容相同的格式时,这才能起作用。否则,您可能不得不进行大量手动配置文件解析或数据库调用,这取决于您的配置参数来自何处。
https://stackoverflow.com/questions/18870779
复制相似问题