我正在尝试替换管道中的日志文件路径
<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 部分中的 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.
因此,您可以将 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/