Hi,
Thanks for the response!
If I’m interpreting correctly, I think the best solution is probably a combination of the Configuration transforms and Substitute variables in files features. It seems a bit complex, but it’s a really common scenario for a situation like this.
First, you’d need a single transformation file called (for example) Log4Net.DeploymentTransform.config
. This transformation would simply target the <file>
element, replacing the value with an Octopus replacement variable. Based on the fragment you’ve given me, I’ll assume your original log4net config file looks something like this:
<?xml version="1.0"?>
<log4net debug="false">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="c:\\Logs\\Log.txt"/>
<appendToFile value="true"/>
</appender>
</log4net>
Your transform file might contain this (note the #{LogFileLocation}
variable):
<?xml version="1.0"?>
<log4net debug="false" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender" xdt:Transform="Replace" xdt:Match="name">
<file value="#{LogFileLocation}" />
<appendToFile value="true" />
</appender>
</log4net>
You could then turn on the “Substitute variables in files” feature, and point at the Log4Net.DeploymentTransform.config
transformation file (variable replacement happens before transformation). That would result in the #{LogFileLocation}
variable being replaced with whatever value was set for your LogFileLocation
variable in the current scope.
You’d also turn on the Configuration transforms feature, and fill out the Additional transforms section in the Configuration Transforms feature to identify your transform file (e.g. Log4Net.DeploymentTransform.config => log4net.config
).
So the variable replacement happens in the transform file, then the transformation happens. This should result in a log4net.config
file with this:
<?xml version="1.0"?>
<log4net debug="false">
<appender name="RollingLogFileAppender"><file value="ThisIsTheValueOfMyVariable" /><appendToFile value="true" /></appender>
</log4net>
I hope this makes sense!
Let me know how you go,
Damo