hryz / Dapper.Logging

Integration of the DbConnection and Asp.Net Core Logging
MIT License
43 stars 15 forks source link

Interpolation string gets logged instead of full string of query and parameters as shown on console. #14

Open carlos0202 opened 3 years ago

carlos0202 commented 3 years ago

I configured Dapper.Logging library to log SQL Server Dapper queries but when checking logs on Kibanna the message is always shown as this: Dapper query: {query} Parameters: {params}, elapsed: {elapsed} ms, context: {@context}, connection: {@connection}

Startup config: image

Console logs: image

Kibana logs: image

Expected result: The Kibana logged message should be the same as the console log.

carlos0202 commented 3 years ago

Is this project abandoned/disbanded? Thanks in advance for any help on this.

hryz commented 3 years ago

Sorry for a really late reply. For some reason, I don't get notifications when somebody opens an issue. Kibana uses 2 separate fields:

carlos0202 commented 3 years ago

Sorry for a really late reply. For some reason, I don't get notifications when somebody opens an issue. Kibana uses 2 separate fields:

  • message = message template,
  • rendered message = message with all placeholder values baked in. This way you can filter out all the messages by their template. Are you sure that there's no rendered message field in the Kibana logs?

Sorry for my late reply as well. Right now, only the message (message template) is being sent to Kibana. How can I Send both parameters to Kibana using NLog? My configuration is as follows:

image

And:

image

But the result is the following:

image

The JSON object sent is missing the rendered message property.

hryz commented 3 years ago

Hello @carlos0202 , I'm not an NLog expert, but it seems like structured logging using requires some additional configuration: https://github.com/NLog/NLog/wiki/How-to-use-structured-logging#using-structured-logging Since the console output is fine, the issue is probably with a JSON/ELK sink configuration. BTW, Serilog has structured logging out of the box and integrates with different sinks, including ELK in a few lines of code. I forgot when I saw other logging frameworks in modern projects the last time.