Search code examples
nlog

NLog config settings renderer not working as expected


Just uploaded a test case app - https://github.com/lsfera/NLog-Demo-cases/tree/master/Net5

I have a configuration section in my appsettings to provide environment specific parameters.

  "LoggingContext": {
    ..
    "ApplicationName": "cool-app",
    "SyslogUrl": "syslog.server.url"
  }

Everything works fine - also the configSetting layout renderer part - except it doesn't work as (I) expected.

     "targets": {
      "file": {
        "type": "AsyncWrapper",
        "target": {
          "wrappedFile": {
            "type": "File",
            "fileName": "${configsetting:item=LoggingContext.ApplicationName}.log"
.......

File name is correctly replaced - as expected - resulting in "cool-app.log".
But when it comes to syslog section:

"syslog": {
...
      "messageSend": {
          "protocol": "tcp",
          "tcp": {
            "server": "${configsetting:item=LoggingContext.SyslogUrl}"
...

server is left in raw format - "${configsetting:item=LoggingContext.SyslogUrl}"

Same issue with target of type "Http" with "URL" parameter "${configsetting:item=LoggingContext.AlertServiceUrl}"

What's wrong in this configuration?
Example project contains the nlog.config xml version - too convenience


Solution

  • NLog.Targets.Syslog ver. 6.0.3 has been released to nuget with Layout-support for Server-property.

    NLog.Targets.HTTP ver. 1.0.16 has been released to nuget with Layout-support for Headers (Right now there is a bug so one have to explict assign Authorization="" on the target).

    <target type="HTTP"
            name="ws"
            Method='POST'
            URL="https://log-api.eu.newrelic.com/log/v1"
            ContentType='application/json'
            Accept='application/json'
            Authorization=''>
        <header name="X-License-Key" value="${environment:LICENSE_KEY}"/>
    </target>