0

不能在 app.config 中重命名标签吗?

如果我使用以下

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

一切都按预期工作(使用 Common Logging 进行记录)。但是,如果我更改部分名称,则忽略配置,例如,如果我将公共组重命名为 mycommon。

<sectionGroup name="mycommon">
  <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
...
<mycommon>
  <logging>
    <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
      <arg key="configType" value="INLINE" />
    </factoryAdapter>
  </logging>
</mycommon>
...

有谁知道诀​​窍吗?

4

2 回答 2

1

也许 XML 路径已连接到 log4net,请尝试询问他们。

于 2010-12-27T21:20:37.007 回答
1

在代码本身中找到了解决方案......

public static class LogManager
{
    /// <summary>
    /// The name of the default configuration section to read settings from.
    /// </summary>
    /// <remarks>
    /// You can always change the source of your configuration settings by setting another <see cref="IConfigurationReader"/> instance
    /// on <see cref="ConfigurationReader"/>.
    /// </remarks>
    public static readonly string COMMON_LOGGING_SECTION = "common/logging";

    private static IConfigurationReader _configurationReader;

所以你可以创建一个实现IConfigurationReader接口的新类,扩展/替换LogManager(或替换字符串,但这需要重新编译Common.Logging)。

感谢Common.Logging 的注释良好的代码......我在调试后得到了它。

于 2010-12-27T22:44:40.183 回答