简体   繁体   English

Web.config转换不起作用

[英]Web.config transform do not work

I'm using SLF and Log4Net for logging. 我正在使用SLF和Log4Net进行日志记录。 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. 我想将以DEBUG模式编译的实例的根记录程序级别设置为ALL,并在为RELEASE构建时将其设置为INFO。 For some reasons, my transform don't works at all. 由于某些原因,我的转换根本不起作用。 Can somebody help me with that transofmation? 有人可以帮助我进行转换吗?

Web.config: 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: 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. 要在尝试执行的部署场景之外运行web.config转换,您可能会发现SlowCheetah Visual Studio软件包很有用。 This package allows you to automatically transform your app.config (or any file) when you press F5 in Visual Studio: 当您在Visual Studio中按F5键时,此软件包可让您自动转换app.config(或任何文件):

Have you ever: 你有没有:

  • Wanted to have different appSettings for debug and release when building your app? 想要在构建应用程序时使用不同的appSettings进行调试和发布吗?
  • 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? 是否想要使用简洁的语法转换任何XML文件?
  • Wanted to tweak WCF service configuration in a straight foward way? 是否想直接调整WCF服务配置?
  • Wanted to preview your XML transform without building/publishing your app? 是否想在不构建/发布应用程序的情况下预览XML转换?
  • Wanted to transform files in addition to web.config on publish for Web projects? 是否想要在发布Web项目时转换除web.config之外的文件?

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 ) (摘自http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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