Parameter substitution in log4net.config file via Variables in Azure DevOps Release

204 Views Asked by At

We have an ASP.NET Core app that we deploy using Azure DevOps Release Pipeline. In that, we change several parameters in some JSON files by setting them in the Variables in the Azure DevOps Release Pipeline.

Our web app uses log4net, which has a separate log4net.config file with a file path in it.

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  ...
  <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender" >
    <file name="LogFilePath" value="../../../App_Data/Logs/Logs.txt" />
    ...
  </appender>
  ...
</log4net>

The default path in LogFilePath is used during local debugging. During deployment, we are trying to change the value to "App_Data/Logs/Logs.txt". We set a Variable with the same name and the new value.

Azure DevOps Release Pipeline Variables

In the Task "Deploy Azure App Service", we have the checkbox "XML variable substitution" checked. Here is how the task looks like:

"workflowTasks": [
                    {
                        "environment": {},
                        "taskId": "xxxx-xxxx-xxxx-xxxx-xxxx",
                        "version": "4.*",
                        "name": "Deploy Azure App Service",
                        "refName": "",
                        "enabled": true,
                        "alwaysRun": false,
                        "continueOnError": false,
                        "timeoutInMinutes": 0,
                        "retryCountOnTaskFailure": 0,
                        "definitionType": null,
                        "overrideInputs": {},
                        "condition": "succeeded()",
                        "inputs": {
                            "ConnectionType": "AzureRM",
                            "ConnectedServiceName": "$(Parameters.ConnectedServiceName)",
                            "PublishProfilePath": "$(System.DefaultWorkingDirectory)/**/*.pubxml",
                            "PublishProfilePassword": "",
                            "WebAppKind": "$(Parameters.WebAppKind)",
                            "WebAppName": "$(Parameters.WebAppName)",
                            "DeployToSlotOrASEFlag": "false",
                            "ResourceGroupName": "",
                            "SlotName": "production",
                            "DockerNamespace": "$(Parameters.DockerNamespace)",
                            "DockerRepository": "$(Parameters.DockerRepository)",
                            "DockerImageTag": "$(Build.BuildId)",
                            "VirtualApplication": "",
                            "Package": "$(System.DefaultWorkingDirectory)/_SPS-main-dev/drop/my-artifact.zip",
                            "RuntimeStack": "",
                            "RuntimeStackFunction": "",
                            "StartupCommand": "$(Parameters.StartupCommand)",
                            "ScriptType": "Inline Script",
                            "InlineScript": "xcopy /s /y /f wwwroot\\dist wwwroot",
                            "ScriptPath": "",
                            "WebConfigParameters": "",
                            "AppSettings": "",
                            "ConfigurationSettings": "",
                            "UseWebDeploy": "true",
                            "DeploymentType": "webDeploy",
                            "TakeAppOfflineFlag": "true",
                            "SetParametersFile": "",
                            "RemoveAdditionalFilesFlag": "true",
                            "ExcludeFilesFromAppDataFlag": "true",
                            "AdditionalArguments": "",
                            "RenameFilesFlag": "true",
                            "XmlTransformation": "false",
                            "XmlVariableSubstitution": "true",
                            "JSONFiles": "**/appconfig.json\n**/appsettings.json"
                        }
                    }
                ]

When we run the Release, we see in the logs that the file is checked but skipped and we see that the value was not replaced.

Release logs

Opening the deployed file shows no change too.

We are not sure what we are missing. Any ideas will be greatly appreciated.

0

There are 0 best solutions below