Nlog: Npgsql Database target parameterType docs are off

Created on 20 Nov 2019  路  11Comments  路  Source: NLog/NLog

NLog version: 4.6.8

Platform: .NET Core 2.1

Current NLog config

{
  "nlog": {
    "autoReload": true,
    "throwExceptions": true,
    "internalLogToConsole": true,
    "internalLogLevel": "Error",
    "variables": {
      "appName": "AbandonedAppEmailAutomation"
    },
    "targets": {
      "Console": {
        "type": "Console",
        "layout": "${level} ${event-properties:EventID:format=tostring} ${callsite:includeSourcePath=false:includeNamespace=false} ${message}",
        "detectConsoleAvailable": false
      },
      "Database": {
        "type": "Database",
        "dbProvider": "Npgsql.NpgsqlConnection, Npgsql",
        "connectionString": "Host=localhost;Database=postgres;Username=postgres;Password=postgres;",
        "commandText": "insert into event (event_type_id, level, exception, system, description, source, callsite, date_created) values (@EventId, @Level, @Exception, @System,  @Description, @Source, @Callsite, CAST(@Date AS timestamp));",
        "parameters": [
          {
            "name": "@System",
            "layout": "${machinename}"
          },
          {
            "name": "@Level",
            "layout": "${level}"
          },
          {
            "name": "@Description",
            "layout": "${message}"
          },
          {
            "name": "@Source",
            "layout": "${appName}"
          },
          {
            "name": "@Callsite",
            "layout": "${callsite}"
          },
          {
            "name": "@EventId",
            "layout": "${event-properties:item=EventId_Id:whenEmpty=6}",
            "dbType": "int64",
            "parameterType": "System.Int64"
          },
          {
            "name": "@Exception",
            "layout": "${exception:format=ToString:innerFormat=ToString}"
          },
          {
            "name": "@Date",
            "layout": "${date:format=yyyy-MM-dd HH\\:mm\\:ss.fff}"
          }
        ]
      }
    },
    "rules": {
      "0": {
        "writeTo": "Console",
        "minlevel": "Info",
        "logger": "*",
        "enabled": true
      },
      "1": {
        "writeTo": "Database",
        "minlevel": "Info",
        "logger": "*",
        "enabled": true 
      }
    }
  }
}
  • The docs say parameterType should be Int64
  • It should actually be System.Int64 like I have specified
  • Are there any workarounds? Yes
database-target question

Most helpful comment

Thanks @snakefoot . I didn't realize I could just edit your wiki. I've made the updates I requested. Thanks for the quick responses, you've been awesome.

All 11 comments

Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better!

Hi, thanks for the report.

I have to check if "int64" means "system.Int64" or "dbtype.int64". I think the latter and maybe there is an issue with Nqsql here.

Update: it means dbtype.int64. Not sure if system.Int64 make sense for a dbtype

Could you please check the internal log if there are log entries (warn level) with

DatabaseTarget: Parameter: '{0}' - Failed to assign DbType={1}

?

Please add the requested info, so we could help you better! (This issue will be closed in 7 days)

I get this in the internal NLog:

DatabaseTarget: Parameter: '@EventId' - Failed to assign DbType=int64

My bad. It is currently case-sensitive. Change your json-config to "dbType": "Int64", and it will work. Will fix this.

Created PR #3732 for NLog ver. 4.7

Thank you for reporting this.

Ah, I see that if I use "Int64" for the DbType, then I don't need to specify the parameterType. Thanks for fixing the library code, but the documentation should be updated for people using older versions of the library.
https://github.com/NLog/NLog/wiki/Database-target#sql-statement

Both the dbType and parameterType examples should use uppercase values. Also, the parameterType needs to start with "System." right now. I don't know if you want to fix that too.

When NLog 4.7 is released, then we will update documentation about DbType no longer being case-sensitive (Btw. the wiki is open for editing)

Thanks @snakefoot . I didn't realize I could just edit your wiki. I've made the updates I requested. Thanks for the quick responses, you've been awesome.

:+1: thanks guys!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

imanushin picture imanushin  路  3Comments

imanushin picture imanushin  路  3Comments

geedsen picture geedsen  路  3Comments

carkov1990 picture carkov1990  路  3Comments

ranjan-2209 picture ranjan-2209  路  3Comments