0

isn't it possible to rename tags within the app.config?

If I use the following

...
<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>
...

everything works as expected (logging with Common Logging is done). But if I change the section names the config is ignored, e.g. if I rename the group common to 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>
...

Anyone knows the trick?

Beachwalker
  • 7,685
  • 6
  • 52
  • 94

2 Answers2

1

Maybe the XML path is wired into log4net, try asking them.

fejesjoco
  • 11,763
  • 3
  • 35
  • 65
  • I think this should be handled by a separate Handler and not wired in the code but I will take a look at common.logging (which acts as a wrapper log4net does not know anything about the common/logging section). – Beachwalker Dec 27 '10 at 21:28
  • By the way, it seems other section handlers can't be renamed as well (e.g. Spring). But I have seen tutorials about custom handlers and the tag were choosen by the developer using the lib (as it should be). In other cases there would be a problem if two libs uses the same section names for their configuration. – Beachwalker Dec 27 '10 at 21:33
  • I had a (quick) look and it is implemented as expected... the first wired element is the factoryAdapter so there is no hard coded common/logging dependency. So your answer doesn't seems to be a solution. But thanx anyway. Any other ideas? – Beachwalker Dec 27 '10 at 21:53
  • If it's not hardwired, then it should just work. Grab the log4net source code, then build and debug it. – fejesjoco Dec 27 '10 at 22:15
  • ... ok, after a deeper look I have found the public static readonly string COMMON_LOGGING_SECTION = "common/logging" in the LogManager which initiated the GetSection call with this param. So you guessed right, thx. – Beachwalker Dec 27 '10 at 22:35
1

The solution was found in the code itself...

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;

So you can create a new class Implementing the IConfigurationReader interface, extend/replace the LogManager (or replace the string, but this requires recompiling Common.Logging).

Thanks for the well commented code of Common.Logging... I got it after debugging.

Beachwalker
  • 7,685
  • 6
  • 52
  • 94
  • It took me half a day to finally understand that was the problem... I've removed the section group and suddenly there were no logging at all. So thanks a lot! – Speuline Nov 03 '16 at 15:12