首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不带app.config的Common.Logging

不带app.config的Common.Logging
EN

Stack Overflow用户
提问于 2013-09-18 19:16:14
回答 1查看 595关注 0票数 3

我正在尝试使用Common.Logging,但我们没有使用app.config,我们的参数在几个xml配置文件或数据库中。

如何告诉Common.Logging从其他文件中获取工厂适配器?

代码语言:javascript
复制
<common>
    <logging>
      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
        <arg key="configType" value="INLINE" />
      </factoryAdapter>
    </logging>
  </common>

我需要从另一个文件中获取此配置节。

有什么建议吗?

最佳回归者卡洪

EN

回答 1

Stack Overflow用户

发布于 2013-09-19 02:04:28

您没有指定Common.Logging的版本,但我假设它是基于2.1的。

我认为你可以通过实现Common.Logging.IConfigurationReader来做到这一点,类似于下面的内容:

代码语言:javascript
复制
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

然后,在应用程序启动时,您可以调用

代码语言:javascript
复制
Common.Logging.LogManager.Reset(New ConfigReader(pathToConfigFile))

当然,只有当您有一个包含所有参数的配置文件,并且它使用与标准Common.Logging内容相同的格式时,这才能起作用。否则,您可能不得不进行大量手动配置文件解析或数据库调用,这取决于您的配置参数来自何处。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18870779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档