xml - 如何访问 log4net 附加程序文件值并在 azure 管道中替换

标签 xml azure azure-devops azure-pipelines azure-pipelines-release-pipeline

我正在尝试替换管道中的日志文件路径

<configuration>
 <configSections>
  <applicationSettings>
   <log4net debug="true">
    <appender name="appender1">
        <file value="log.txt"/>
    </appender>
   </log4net>
  </applicationSettings>
 </configSections>
</configuration>

我正在使用FileTransform任务来实现这一点。 如何访问 log4net 附加程序文件值并在 azure 管道中替换 在变量中设置的“名称”应为“什么”和“如何”。 我希望将“值”设置为“D:\Logs\log.txt”。谢谢。

最佳答案

正如 FileTransform task document 中所述。管道中定义的变量将与 appSettings、applicationSettings 和 connectionStrings 部分中的 keyname 条目进行匹配。

Variables defined in the build or release pipelines will be matched against the 'key' or 'name' entries in the appSettings, applicationSettings, and connectionStrings sections of any config file and parameters.xml. Variable Substitution is run after config transforms.

因此,您可以将 name 属性添加到配置文件中的 file 属性。例如下面的例子。我添加了一个名称属性 LogFile:

 <applicationSettings>
   <log4net debug="true">
    <appender name="appender1">
        <file name="LogFile" value="log.txt"/>
    </appender>
   </log4net>
  </applicationSettings>

然后,您可以在 azure devops 管道的变量部分定义一个名为 LogFile 的变量。请参阅下面的示例:

variables:
  LogFile: D:\Logs\log.txt

steps:
- task: FileTransform@1
  inputs:
    folderPath: $(System.DefaultWorkingDirectory)
    fileType: xml
    

如果您不想将 name 属性添加到 file 属性。您可以使用任务Magic Chuncks替换 file 属性的值。

设置转换:configuration/configSections/applicationSettings/log4net/appender/file/@value": "D:\Logs\log.txt"。见下文示例:

参见here关于如何转换XML文件

steps:
- task: sergeyzwezdin.magic-chunks.magic.chunks.MagicChunks@2
  displayName: 'Config transform'
  inputs:
    sourcePath: '$(System.DefaultWorkingDirectory)/path/to/app.config'
    transformations: |
     {
       "configuration/configSections/applicationSettings/log4net/appender/file/@value": "D:\Logs\log.txt"
      }

关于xml - 如何访问 log4net 附加程序文件值并在 azure 管道中替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65077323/

相关文章:

java - 如何在 JAXB MARSHALLING 期间修剪字符串

android - 我可以使用相同的“radioButton_states”drawable 并创建一个每个按钮具有不同背景颜色的 radioGroup 吗?

asp.net - Azure ReportViewer 在 DevFabric 中工作正常,但在 Azure 部署中引发异常

azure - 如何测试 Azure Pipelines

flutter - Azure DevOps 项目直接发布到 google play 控制台

iis - Azure 网站部署到已经有 "Default web site"的机器

java - Android Studio 无法解析符号

xml - 这些名为 "#text"的 XML 节点发生了什么?

azure - 用于 Selenium 测试的 Team Foundation 服务器自定义托管构建 Controller

azure - 在浏览器中显示 Azure blob 图像文件并且不强​​制下载