NLog and SQLite Error

1.1k views Asked by At

I am trying to get NLog to properly log to a SQLite database.
I am able to interact with the SQLite database aside from NLog.

When I force Internal Logging of NLog, I see the following error:

Error initializing target Database Target[db] System.TypeLoadException: Could not load type 'System.Data.SQLite' from assembly 'NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c'.

My NLog configuration has the following parameters:

  • dbProvider="System.Data.SQLite" keepConnection="false"
  • connectionString="Data Source=${basedir}\Database.s3db;"
  • commandText="INSERT into Log(Timestamp, Loglevel, Logger, Callsite, Message) values(@Timestamp, @Loglevel, @Logger, @Callsite, @Message)"

What am I missing?

3

There are 3 answers

0
Todd Zetlan On

I changed the NLog configuration to point to System.Data.SQLite.EF6 as the dbProvider and it is working now.

0
Sadjad Esfandiari On

Install the following nuget package : Install-Package System.Data.SQLite -Version 1.0.115

0
S.ATTA.M On

Its a very old question but my answer might help if anyone else faces the same issue:

In my case the version number in NLog.config file was the issue which was not the one what I have added System.Data.SQLite.dll. To do so:

  • Right click on System.Data.SQLite.dll and then click Properties
  • Click Details for actual version number
  • Write correct version in NLog.config file

enter image description here

enter image description here