Search code examples
jsonweb-servicesnlogslack

How to JsonPost to a WebService target in Nlog


With Nlog 4.4.5 am trying to use protocol JsonPost of WebService target to post logs to slack. Slack webhooks need Json data over https post (https://api.slack.com/incoming-webhooks)

<target xsi:type="WebService"
            name="slack"
            url="https://hooks.slack.com/services/T*****/B4T****/7F********XDv9h/"
            protocol="JsonPost"
            encoding="utf-8"
            >

    <parameter name="text" type="System.String" layout="${date:format=yyyy-MM-dd HH\:mm\:ss.fff}: ${level} - ${message}"/> 

</target>

It does not post anything to my slack channel created for the webhook whereas I see the other targets in my Nlog.config are called and log files are populated with new data.

Any idea where I should look into to sort it out?


Solution

  • The problem was with the ending "/" in the Slack webhook url. Removed and it started posting logs to my slack channel.