【问题标题】:WCF Web.Configuration Transformation - How to Write?WCF Web.Configuration 转换 - 如何编写?
【发布时间】:2018-07-15 22:58:07
【问题描述】:

我的 WCF 项目中有一个 web.configuration 文件。内容包含这样的语句:

  <system.diagnostics>
    <sources>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="Warning,ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="c:\ModelInfo\LightZ.svclog"
        type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>

我想要在我的部署配置文件中做的就是用不同的名称替换日志文件。例如:LightZ-2.svclog。

如何编写转换文件?也就是说,我如何填写以下空白以实现这一目标。我尝试了很多版本和/或教程,但仍然没有任何线索。

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <!--
    In the example below, the "SetAttributes" transform will change the value of 
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
    finds an attribute "name" that has a value of "MyDB".

    <connectionStrings>
      <add name="MyDB" 
        connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
  -->
  <system.web>
    <!--
      In the example below, the "Replace" transform will replace the entire 
      <customErrors> section of your web.config file.
      Note that because there is only one customErrors section under the 
      <system.web> node, there is no need to use the "xdt:Locator" attribute.

      <customErrors defaultRedirect="GenericError.htm"
        mode="RemoteOnly" xdt:Transform="Replace">
        <error statusCode="500" redirect="InternalError.htm"/>
      </customErrors>
    -->
  </system.web>
</configuration>

【问题讨论】:

    标签: wcf web deployment configuration


    【解决方案1】:
    <?xml version="1.0" encoding="utf-8"?>
    
    <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
    
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <!--
        In the example below, the "SetAttributes" transform will change the value of 
        "connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
        finds an attribute "name" that has a value of "MyDB".
    
        <connectionStrings>
          <add name="MyDB" 
            connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
            xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
        </connectionStrings>
      -->
      <system.diagnostics>
        <sharedListeners>
          <add initializeData="C:\ModelInfo\LightZ_athena.svclog" xdt:Transform="Replace" 
               type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
               name="ServiceModelTraceListener" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack">
            <filter type="" />
          </add>
        </sharedListeners>
      </system.diagnostics>
    </configuration>
    

    【讨论】:

    • 您能否对您的代码/xml 配置所做的工作添加一些评论?
    猜你喜欢
    • 2022-09-27
    • 2020-11-11
    • 1970-01-01
    • 2014-07-05
    • 2012-06-28
    • 1970-01-01
    • 2010-10-31
    • 2021-01-17
    • 2011-02-08
    相关资源
    最近更新 更多