title: NLog Database Target for .net Core 2.0
body: <p>I am trying to write various logs to database and to files using NLog in .net Core 2.0 . The thing is, writing logs to files working perfectly fine. But I always get following error when writing logs to database:</p>
  
  <blockquote>
    <p>2018-01-10 08:48:29.5666 Error Error initializing target 'Database Target[db]'. Exception: System.TypeLoadException: Could not load type 'System.Data.SqlClient' from assembly 'NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c'.
            at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
            at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
            at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark&amp; stackMark)
            at System.Type.GetType(String typeName, Boolean throwOnError)
            at NLog.Targets.DatabaseTarget.SetConnectionType()
            at NLog.Targets.DatabaseTarget.InitializeTarget()
            at NLog.Targets.Target.Initialize(LoggingConfiguration configuration)</p>
  </blockquote>
  
  <p>But I have <b>System.Data.SqlClient</b> in my project as follow: </p>
  
  <pre class="lang-cs prettyprint-override"><code>&lt;ItemGroup&gt;
      &lt;PackageReference Include="EPPlus.Core" Version="1.5.4" /&gt;
      &lt;PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.2.0-beta3" /&gt;
      &lt;PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" /&gt;
      &lt;PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.1" /&gt;
      &lt;PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.0.1" /&gt;
      &lt;PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.1" /&gt;
      &lt;PackageReference Include="Microsoft.AspNetCore.Session" Version="2.0.1" /&gt;
      &lt;PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" PrivateAssets="All" /&gt;
      &lt;PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.1" PrivateAssets="All" /&gt;
      &lt;PackageReference Include="NLog" Version="4.5.0-rc03" /&gt;
      &lt;PackageReference Include="NLog.Web.AspNetCore" Version="4.5.0-rc2" /&gt;
      &lt;PackageReference Include="System.ComponentModel" Version="4.3.0" /&gt;
      &lt;PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0-preview1-25914-04" /&gt;
      &lt;PackageReference Include="System.Data.SqlClient" Version="4.4.2" /&gt;
  &lt;/ItemGroup&gt;
  </code></pre>
  
  <p>My NLOG code:  </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true" internalLogLevel="info" internalLogFile="C:\*****\Log2\asdaf.log"&gt;
  &lt;targets&gt;
      &lt;target
          xsi:type="File"
          name="allfile"
          fileName="C:\*****\Logs\${shortdate}.log"
          layout="${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message} ${exception}" &gt;
      &lt;/target&gt; 
  
      &lt;target xsi:type="Database" name="db"&gt;
          &lt;commandText&gt;INSERT INTO [LogEntries](TimeStamp, Message, Level, Logger) VALUES(getutcdate(), @msg, @level, @logger)&lt;/commandText&gt;
          &lt;parameter name="@msg" layout="${message}" /&gt;
          &lt;parameter name="@level" layout="${level}" /&gt;
          &lt;parameter name="@logger" layout="${logger}" /&gt;
          &lt;dbProvider&gt;System.Data.SqlClient&lt;/dbProvider&gt;
          &lt;connectionString&gt;*****&lt;/connectionString&gt;
      &lt;/target&gt;
  
      &lt;target xsi:type="Null" name="blackhole" /&gt;
  &lt;/targets&gt;
  &lt;rules&gt;
      &lt;logger name="*" minlevel="Trace" writeTo="allOutputs" /&gt;
      &lt;logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" /&gt;
      &lt;logger name="*" minlevel="Trace" writeTo="ownFile-web" /&gt;
  &lt;/rules&gt;
  &lt;/nlog&gt;
  </code></pre>
  
  <p>I searched for this issue on Github but none of the solutions worked for me. And getting System.Data.SqlClient from Nuget should be enough but unfortunately, Mr. Nlog.config want someting else and I couldn't find out what.</p>