1
votes

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>

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.

1
Can you show your pipeline and your transformation definition?Krzysztof Madej

1 Answers

1
votes

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.

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.

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>

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
    

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.

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

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