.net 不带app.config的Common.Logging
我尝试使用Common.Logging,但我们不使用app.config,我们的参数在几个xml配置文件或数据库中 如何告诉Common.Logging从其他文件获取工厂适配器.net 不带app.config的Common.Logging,.net,vb.net,logging,config,common.logging,.net,Vb.net,Logging,Config,Common.logging,我尝试使用Common.Logging,但我们不使用app.config,我们的参数在几个xml配置文件或数据库中 如何告诉Common.Logging从其他文件获取工厂适配器 <common> <logging> <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net"> <arg
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
我需要从其他文件获取此配置部分
有什么建议吗
最佳再培训
Cajon您没有指定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文件相同的格式时,这才有效。否则,根据配置参数的来源,您可能必须执行一系列手动配置文件解析或数据库调用