ASP.NET 配置转换不工作

ASP.NET Configuration Transform not working

这是我的(缩写)Web.config

<configuration>
  [...]
  <nlog autoReload="true" throwExceptions="false" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
      <target xsi:type="File" name="file" layout="[...]" />
    </targets>
    <rules>
      <logger name="*" minlevel="Trace" writeTo="file" />
    </rules>
  </nlog>
</configuration>

这是我的Web.Release.Config

<configuration>
  <nlog>
    <rules>
      <logger name="*" minlevel="#{Something}#" writeTo="file" xdt:Transform="SetAttributes" xdt:Locator="Match(writeTo)" />
    </rules>
  </nlog>
</configuration>

但是没有任何转换发生。我也看不到 ConfigurationTransform 输出中的任何错误或警告 window...

我做错了什么?

问题是发布配置中的 nlog 元素在不同的 namespace 中,您需要包括:

<configuration>
  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd">
    <rules>
      <logger name="*" minlevel="#{Something}#" writeTo="file"
          xdt:Transform="SetAttributes" xdt:Locator="Match(writeTo)" />
    </rules>
  </nlog>
</configuration>