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 の名前を 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

解決策はコード自体にありました...

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 に答える
1

XML パスが log4net に配線されている可能性があります。問い合わせてみてください。

于 2010-12-27T21:20:37.007 に答える