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)
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0
