title: log4net with SQLite: InvalidCastException: Unable to cast object of type 'System.Data.SQLite.SQLiteFactory' to type 'System.Data.IDbConnection'
body: <p>Using log4net, When i try to open a SQLite database under App_Data folder in my Asp.net application am getting this following error in trace file.</p>
  
  <blockquote>
    <p>log4net:ERROR [AdoNetAppender] ErrorCode: GenericFailure. Could not
    open database connection [Data
    Source=|DataDirectory|\databasefile1.db;Synchronous=Off]. Connection
    string context [ConnectionString]. System.InvalidCastException: Unable
    to cast object of type 'System.Data.SQLite.SQLiteFactory' to type
    'System.Data.IDbConnection'. at
    log4net.Appender.AdoNetAppender.CreateConnection(Type connectionType,
    String connectionString) at
    log4net.Appender.AdoNetAppender.InitializeDatabaseConnection()</p>
  </blockquote>
  
  <p>Version Details:</p>
  
  <ul>
  <li>.NET Framework 4.5.1</li>
  <li>SQLite 1.0.93.0</li>
  <li>log4net 1.2.11.0</li>
  </ul>
  
  <p>I tried changing my sqlite database location but same error occur.</p>
  
  <p>in Global.asax.cs,</p>
  
  <pre><code>void Application_Start(object sender, EventArgs e)
      {
          AppDomain.CurrentDomain.SetData("DataDirectory", Server.MapPath("~/"));
          XmlConfigurator.Configure(); 
      }
  </code></pre>
  
  <p>in AssemblyInfo.cs,</p>
  
  <pre><code>[assembly: log4net.Config.XmlConfigurator(ConfigFile="Web.config", Watch= true)]
  </code></pre>
  
  <p>In Web.config</p>
  
  <pre><code>&lt;log4net debug="true"&gt;&lt;appender name="sqlite" type="log4net.Appender.AdoNetAppender"&gt;&lt;bufferSize value="1"/&gt;&lt;connectionType value="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.93.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"/&gt;&lt;connectionString value="Data Source=|DataDirectory|\databasefile1.db;Synchronous=Off"/&gt;&lt;commandText value="INSERT INTO LogTable(message) VALUES (@message)"/&gt;&lt;parameter&gt;&lt;parameterName value="@message"/&gt;&lt;dbType value="String"/&gt;&lt;layout type="log4net.Layout.PatternLayout"&gt;&lt;conversionPattern value="%message"/&gt;&lt;/layout&gt;&lt;/parameter&gt;&lt;/appender&gt;&lt;root&gt;&lt;level value="ALL"/&gt;&lt;appender-ref ref="sqlite"/&gt;&lt;/root&gt;&lt;/log4net&gt;
  </code></pre>