在发布时更改.config文件中的附加程序参数值(Azure管道) [英] Change appender param value in .config files on release ( azure pipelines)

查看:111
本文介绍了在发布时更改.config文件中的附加程序参数值(Azure管道)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用log4net登录.net解决方案中的几乎所有项目. 目前,我已经配置了一个附加程序(AzureTableAppender),该配置是在每个项目各自的app.config/web.config中进行的. 该附加程序具有一个名为"TableName"的参数,并带有一个关联的值,该值表示向其发送数据的表.一切正常,但是我想更改我的2个发行版中的值,因为我想要其他地方的日志.
配置看起来像这样:

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>

总而言之,我想更改所有.config文件(应用程序,Web)的"TableName"值,具体取决于发行版. 我在发布中使用Azure Pipelines. (当我使用gui中的管道变量时,我想到了这一点,但我认为这些目标仅针对appSettings,connectionStrings)

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.将<log4net>元素的内容更改为以下格式:

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.创建两个具有不同内容的变量组(一个用于DEV,另一个用于Release).在您的发布管道中,链接它们并选择相应的范围:

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:

执行Replace Token task时,它将用相应的值替换#{MyTable}##{MyRelease}#.(请注意,此任务在xx.zip文件中的文件中不起作用)希望对您有所帮助,如果我误解了您的要求,请随时纠正我.

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.

这篇关于在发布时更改.config文件中的附加程序参数值(Azure管道)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆