title: Setting up dynamic connection string for log4net
body: <p>I am using log4net and I am have a connection string I want to reference in my log4net config, because the connectionString in "/Config/connectionStrings.config" will be dynamic input from the user.</p>
  
  <p>Here is what I am trying to do:</p>
  
  <pre><code> &lt;log4net xmlns="log4net"&gt;
      &lt;root&gt;
       &lt;level value="ERROR" /&gt;
       &lt;appender-ref ref="DatabaseAppender" /&gt;
     &lt;/root&gt;
  
  &lt;appender name="DatabaseAppender" type="log4net.Appender.AdoNetAppender"&gt;
    &lt;bufferSize value="100" /&gt;
    &lt;connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&gt;
    &lt;connectionStrings configSource="Config\ConnectionStrings.config" /&gt;
    &lt;commandText value="INSERT INTO dm.ErrorLogs ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" /&gt;
    &lt;parameter&gt;....
   &lt;/appender&gt;
   &lt;/log4net&gt;
  </code></pre>
  
  <p>Log4net expects something like this in the connectionStrings:</p>
  
  <pre><code>&lt;connectionString value="data source=SQLSVR;initial catalog=test_log4net;integrated security=false;persist security info=True;User ID=sa;Password=sa" /&gt;
  </code></pre>
  
  <p>My reference config:
  Config\ConnectionStrings.config
  All of which is input from the user, so I need the connectionString value of the second connectionString attribute which is</p>
  
  <p>"Data Source=(local);Initial Catalog=DbTwo;Integrated Security=True;MultipleActiveResultSets=True;Application Name=AppName2". </p>
  
  <p>Is there a way to get this value using ASP.NET C#, so I can create a database appender in code? Or is there another I cold do this in the log4net.config?</p>
  
  <pre><code>   &lt;connectionStrings&gt;
     &lt;add name="Connection1" 
      connectionString="Data Source=(local);Initial Catalog=DbOne;Integrated Security=True;Application Name=AppName1" 
       providerName="System.Data.SqlClient" /&gt;
     &lt;add name="Connection2" 
       connectionString="Data Source=(local);Initial Catalog=DbTwo;Integrated Security=True;MultipleActiveResultSets=True;Application Name=AppName2" 
       providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p></p>