如何在Azure管道中访问log4net附加程序文件值并进行替换 [英] How to access log4net appender file value and replace in the azure pipelines

查看:52
本文介绍了如何在Azure管道中访问log4net附加程序文件值并进行替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to replace log file path from pipeline

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

我正在使用 FileTransform 任务来实现这一目标.如何在Azure管道中访问log4net附加程序文件值并进行替换名称"应该是什么以及如何命名?在变量中设置.我想要价值"设置为"D:\ Logs \ log.txt".谢谢.

I am using FileTransform task to achieve this. How to access log4net appender file value and replace in the azure pipelines What and How should be the "Name" to be set in the variable. I want the "Value" to be set as "D:\Logs\log.txt". Thanks.

推荐答案

As it is described in the FileTransform task document. The variables defined in pipeline will be matched against the key or name entries in the appSettings, applicationSettings, and connectionStrings sections.

在构建或发布管道中定义的变量将与任何配置文件和parameters.xml的appSettings,applicationSettings和connectionStrings部分中的"key"或"name"条目匹配.在配置转换后运行变量替换.

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.

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

So you can add a name attribute to the file property in your config file. For example in below. I add a name attribute LogFile:

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

然后,您可以在azure devops管道的变量"部分中定义一个名为 LogFile 的变量.参见以下示例:

Then you can define a variabled named LogFile in Variables section of your azure devops pipeline. See below example:

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

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

如果您不想在 file 属性中添加 name 属性.您可以使用任务魔术块替换的值文件属性.

If you donot want to add a name attribute to file property. You can use Task Magic Chuncks to replace the value of file property.

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

Set the transformations: configuration/configSections/applicationSettings/log4net/appender/file/@value": "D:\Logs\log.txt". See below example:

有关如何转换XML文件的信息,请参见此处/p>

See here about how to transform XML files

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"
      }

这篇关于如何在Azure管道中访问log4net附加程序文件值并进行替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆