问题
I am using log4net for logging on almost all projects in my .net solution.
Currently, I have configured an appender (AzureTableAppender), configuration that is made in each project's respective app.config/ web.config.
This appender has a param named "TableName", with an associated value that represents the table to which the data is sent. Everything works fine, but I would like to change that value for 2 of my releases as I want the logs somewhere else.
The config looks like this:
<log4net>
<appender type="log4net.Appender.AzureTableAppender.......
<param name = "TableName" value = "MyTable" />
....
</log4net>
To sum up, I would want to change the "TableName" value for all .config files(app, web), depending on release. I am using Azure Pipelines for my releases . ( as I use pipeline variables from gui I thought of that, but I think those target only appSettings, connectionStrings)
回答1:
You can try Replace Token task.
1.Change your content of <log4net>
element to this format:
<log4net>
<appender type="log4net.Appender.AzureTableAppender.......
<param name = "TableName" value = "#{MyTable}#" />
<param name = "ReleaseName" value = "#{MyRelease}#" />
</log4net>
2.Create two variable groups(one for DEV
and another for Release
) with different content. In your release pipeline link them and choose corresponding scope:
When the Replace Token task
executes, it will replace the #{MyTable}#
and #{MyRelease}#
with corresponding value.(Note this task won't work in files inside xx.zip file) Hope it helps and if I misunderstand your requirements, feel free to correct me.
来源:https://stackoverflow.com/questions/60169604/change-appender-param-value-in-config-files-on-release-azure-pipelines