简体   繁体   中英

Web.config transform do not work

I'm using SLF and Log4Net for logging. I want to have the root logger level set to ALL for an instance compiled in DEBUG mode and set to INFO when built for RELEASE. For some reasons, my transform don't works at all. Can somebody help me with that transofmation?

Web.config:

<configuration>

  <configSections>
    <section name="slf"
             type="Slf.Config.SlfConfigurationSection, slf"/>
    <section name="log4net"
             type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
  </configSections>

  <slf>
    <factories>
      <!-- log everything through the Log4netFacade -->
      <factory type="SLF.Log4netFacade.Log4netLoggerFactory, SLF.Log4netFacade"/>
    </factories>
  </slf>

  <log4net>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="C:\logging\log.txt" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="1MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %logger %username %level%newline - %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="INFO" />
      <appender-ref ref="RollingFileAppender" />
    </root>
  </log4net>

<!-- truncated web.config here -->

</configuration>

Web.Debug.config:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <log4net>
    <root>
      <level value="ALL"
        xdt:Transform="Replace"
        xdt:Locator="XPath(configuration/log4net/root/level[@value='INFO'])" />
    </root> 
  </log4net>

  <system.web>
  </system.web>
</configuration>

Thanks!

To run a web.config transform outside a deployment scenario as you're trying to do, you may find the SlowCheetah Visual Studio package useful. This package allows you to automatically transform your app.config (or any file) when you press F5 in Visual Studio:

Have you ever:

  • Wanted to have different appSettings for debug and release when building your app?
  • Wanted to use different connection strings based on your build configuration when building your app?
  • Wanted to transform any XML file with a clean and simple syntax?
  • Wanted to tweak WCF service configuration in a straight foward way?
  • Wanted to preview your XML transform without building/publishing your app?
  • Wanted to transform files in addition to web.config on publish for Web projects?

If you answered Yes to any of these then you should download this package.

(from http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM