NLog.Extensions.Logging: ConnectionStringName not supported on NLog DatabaseTarget with NetCore

Hi, I get an error:

2016-08-24 10:32:55.0195 Error Error has been raised. Exception: System.NotSupportedException: Parameter connectionStringName not supported on DatabaseTarget

Can’t i use <target name="database" xsi:type="Database" connectionStringName="logConnection"> in a Core app?

logConnection is configured in the JSON config file.

Also for

  <target name="file"
      xsi:type="File"
      fileName="${basedir}/Logs/${shortdate}.txt"
      layout="${date:format=dd.MM.yyyy hh\:mm\:ss} [${level}] ${newline} ${newline} [${callsite}] ${newline} ${message} ${newline} ${newline} ${stacktrace} ${newline} ${newline}${exception:format=ToString} ${newline} ${newline}" />

I don’t get any output.

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

@mottykohn connectionStringName is for .NetFramework and app.config. When using .NetCore and appsetting.json then you can make use of ${configsetting}. Like this:

<targets>
    <target type="database" name="db" connectionString="${configsetting:item=ConnectionStrings.MyDatabase}">
    </target>
</targets>

It will lookup the value in appsettings.json:

{
  "ConnectionStrings": {
    "MyDatabase": "server=localhost;Database=*****;user id=****;password=*****"
  }
}

See also: https://github.com/NLog/NLog/wiki/ConfigSetting-Layout-Renderer

Thanks, that worked!