2015年5月31日 星期日

Log4Net採用現在資料庫的方法

延用上一篇Log4Net記錄log除錯方式(MS-SQL)在Log4Net Appender的資料庫連線字串,會有自己的資料庫連線字串

但是若本身就有有原有的資料庫時,這時要改變資料庫,則設要調整兩個連線字串的地方,那是否會有辦法可以讓Log4Net去捉取我原有的連線字串呢?辦法還是有的

若我本身的資料庫連線字串為

<connectionstrings>
       <add connectionstring="Data Source=127.0.0.1;Initial Catalog=[DataBaseName];User ID=[UserID];Password=[PassWord];Persist Security Info=True;Timeout=2" name="Connection1">
</add></connectionstrings>


而原有的Log4Net的連線方式,只需要新增一個connectionStringName,然後把connectionString拿掉


<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
      <buffersize value="1">
      <connectiontype value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <!--調整的地方-->
      <connectionstringname value="Connection1">

      <!--拿掉的地方-->
      <!--<connectionstring value="data source=127.0.0.1;initial catalog=[DataBaseName];integrated security=false;persist security info=True;User ID=[UserID];Password=[PassWord] />-->

</connectionstringname></connectiontype></buffersize></appender> 



沒有留言:

張貼留言