I am trying to change a log file name after deploying, so transform this:
<log4net>
...
<appender name="GeneralAppender" type="log4net.Appender.RollingFileAppender, log4net">
<file value="c:\logs\Co.App.log" />
...
</appender>
</log4net>
to this:
<log4net>
...
<appender name="GeneralAppender" type="log4net.Appender.RollingFileAppender, log4net">
<file value="c:\logs\Co.App.localhost.log" />
...
</appender>
</log4net>
the actual file node doesn't have any attributes, so I am trying to locate it by parent node
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<log4net>
<appender >
<file value="c:\logs\Co.App.localhost.log" xdt:Transform="Replace" xdt:Locator="XPath(../appender[@name='GeneralAppender'])" />
</appender>
</log4net>
</assemblyBinding>
</runtime>
i've also tried all permutations of absolute and relative xpath's but i don't see it having any effect in transform preview.
i tried:
xdt:Locator="XPath(//appender[@name='GeneralAppender']/file)"
and even:
xdt:Transform="Remove" xdt:Locator="XPath(//file)"
found it!
<file value="c:\logs\Co.App.local.log" xdt:Transform="Replace" xdt:Locator="Condition(../@name='GeneralAppender')" />
Slight extension:
If the parent node has TWO (or more children), then the above solution is not enough.
This is the case in log4net, when the EventLogAppend is used, which has:
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
...
<param name="LogName" value="MyLog"/>
<param name="ApplicationName" value="MyApplication"/>
...
Then you need to use an 'and' + an atribute more to hit the right node:, like xdt:Locator="Condition(../@name='EventLogAppender' and @name='LogName')
Example for the EventLogAppender, where both the params are replaced:
<param name="LogName" value="MyNewLog" xdt:Transform="Replace" xdt:Locator="Condition(../@name='EventLogAppender' and @name='LogName')" />
<param name="ApplicationName" value="MyNewApplication" xdt:Transform="Replace" xdt:Locator="Condition(../@name='EventLogAppender' and @name='ApplicationName')" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With