【问题标题】:How to JsonPost to a WebService target in Nlog如何 JsonPost 到 Nlog 中的 WebService 目标
【发布时间】:2017-03-31 04:54:52
【问题描述】:

在 Nlog 4.4.5 中,我尝试使用 WebService 目标的协议 JsonPost 将日志发布到 slack。 Slack webhook 需要通过 https 发布的 Json 数据 (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>

它不会向我为 webhook 创建的松弛通道发布任何内容,而我看到我的 Nlog.config 中的其他目标被调用并且日志文件中填充了新数据。

知道我应该在哪里进行整理吗?

【问题讨论】:

标签: json web-services nlog slack


【解决方案1】:

问题在于 Slack webhook url 中的结尾“/”。删除并开始将日志发布到我的松弛频道。

【讨论】:

    【解决方案2】:

    可能是这样的答案:

    https://github.com/NLog/NLog/issues/1958

    等待此问题解决(直接使用 JSON-Layout):

    https://github.com/NLog/NLog/issues/1905

    【讨论】:

    • 我想我只需要确保布局生成的json数据格式正确即可。希望我能把它登录到 NLog 的内部日志中吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多