1

I need to change the conf file path depending on the environment. In my Gobal.asaw.cs i have :

log4net.Config.XmlConfigurator.Configure();

In my web.config :

 <add key="log4net.Config" value="conf/Log4netDev.config"/>
 <add key="log4net.Config.Watch" value="True"/>

In my web.Debug.config :

<add key="log4net.Config" value="conf/Log4netDev.config" xdt:Locator="Match(key)" xdt:Transform="Replace" />
<add key="log4net.Config.Watch" value="True" xdt:Locator="Match(key)" xdt:Transform="Replace"/>

In my web.Release.config :

<add key="log4net.Config" value="conf/Log4netRelease.config" xdt:Locator="Match(key)" xdt:Transform="Replace" />
<add key="log4net.Config.Watch" value="True" xdt:Locator="Match(key)" xdt:Transform="Replace"/>

So in my web.config, the log4net.Config value is same as in web.debug.config With visual studio, if i run in debug, i can find my logFile where it's supposed to be, everything is ok. If i run in release, no log file...

I've tried to replace the log4net.Config value in web.config with the value i have in web.release.config, and now : when i run project in Release i have my log file and not in debug anymore. What i understand is this only work when the value is in the web.config

Lempkin
  • 1,458
  • 2
  • 26
  • 49
  • Web Config Transformation does not work, when you run your application with Visual Studio. It means that works default settings inside web.config . – Michael Jan 11 '16 at 16:23
  • Crap... Thx anyway =) – Lempkin Jan 11 '16 at 16:51
  • Possible duplicate of [How to add config transformations for a custom config file in Visual Studio?](http://stackoverflow.com/questions/34735132/how-to-add-config-transformations-for-a-custom-config-file-in-visual-studio) – Michael Jan 15 '16 at 11:31

1 Answers1

1

Why not change it programmatically ?

    var loggingConfigurationFile = HttpContext.Current.IsDebuggingEnabled ? "conf/Log4netDev.config" : "conf/Log4netRelease.config";
    log4net.Config.XmlConfigurator.Configure(new FileInfo(loggingConfigurationFile));
Fab
  • 14,327
  • 5
  • 49
  • 68