我真的很难让这个工作。我可以使用powershell更新应用程序设置,但我需要在Target节点中修改一行。这是我的部分xml
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory,
EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true">
<targets>
<target name="f1" xsi:type="File" fileName="test.log.txt" layout="${threadname}
${longdate} ${callsite} ${logger}[${level}] ${message}" />
<target name="console" xsi:type="Console" layout="${threadname} ${longdate} ${callsite}
${logger}[${level}] ${message}" />
</targets>
<rules>
<!--<logger name="Quartz.*" level="Warn" />-->
<logger name="*" writeTo="f1" minlevel="Info" />
<logger name="*" writeTo="console" minlevel="Debug" />
</rules>
</nlog>
在目标节点中,它说test.log.txt我只想拥有一个文件路径,如&#34; c:\ project \ logs \ test.log.txt&#34;
这是我用于应用程序设置的工具
$webConfig = 'C:\Projects\app.exe.config'
$webConfigXml = [xml](gc $webConfig
$appSetting = $webConfigXml.configuration.appSettings.add | where {$_.Key -eq 'userName'}
$appSetting.value = 'testUser'
在这个问题上苦苦挣扎
答案 0 :(得分:1)
您可以执行以下操作:
$xml = [xml](gc $webConfig)
$t = $xml.getElementsByTagName("targets")
$t.target | % { if ($_.fileName -eq 'test.log.txt') {$_.setAttribute('fileName','c:\project\logs\test.log.txt')} }
$xml.outerXml | Out-File $webConfig
选择所需节点的方式略有不同,但应该按照自己的意愿行事。