我能够转换我的log4net.config,但我没有得到这个。如何更改以下connectionString?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net debug="true">
<root>
<level value="ALL" />
</root>
<logger name="MyApp">
<level value="Debug" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="AdoNetAppender" />
</logger>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\Websites\Logs\SiteLog.txt"/>
<appendToFile value="true"/>
<rollingStyle value="Date"/>
<datePattern value="yyyyMMdd.txt"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
</layout>
</appender>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="***Data Source=(local);initial catalog=MyDB;User ID=sa;Password=dbPassword***" />
以下不起作用:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<log4net debug="false"
xdt:Transform="SetAttributes(debug)" />
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<connectionString value="Data Source=(local);initial catalog=RavenAxiom;User ID=ravenaxiom;Password=xyz"
xdt:Transform="SetAttributes(value)" />
</appender>
</configuration>
它会更改调试值,使其部分有效。感谢您的帮助。
杰克
答案 0 :(得分:43)
好的,让它使用xdt:Locator="Match(name)"
中的appender name="AdoNetAppender"
然后xdt:Transform="Replace"
中的connectionString value="NewConnValues"
。
<configuration>
<log4net>
<appender name="AdoNetAppender"
type="log4net.Appender.AdoNetAppender"
xdt:Locator="Match(name)">
<connectionString value="YourConnectionStringToBe"
xdt:Transform="Replace"/>
</appender>
</log4net>
</configuration>