【问题标题】:NLog config settings renderer not working as expectedNLog 配置设置渲染器未按预期工作
【发布时间】:2021-03-21 09:08:29
【问题描述】:

刚刚上传了一个测试用例应用 - https://github.com/lsfera/NLog-Demo-cases/tree/master/Net5

我的appsettings 中有一个配置部分,用于提供特定于环境的参数。

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

一切正常——还有 configSetting 布局渲染器部分——除了它没有按(我)预期的那样工作。

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

文件名被正确替换 - 正如预期的那样 - 导致“cool-app.log”。
但是当涉及到系统日志部分时:

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

服务器保留原始格式 - “${configsetting:item=LoggingContext.SyslogUrl}”

带有“URL”参数“${configsetting:item=LoggingContext.AlertServiceUrl}”的“Http”类型目标的相同问题

这个配置有什么问题?
示例项目包含nlog.config xml 版本 - 太方便了

【问题讨论】:

标签: nlog


【解决方案1】:

NLog.Targets.Syslog ver. 6.0.3 已成为 released to nugetLayout-support for Server-property

NLog.Targets.HTTP 版本。 1.0.16 一直是released to nuget,带有对标题的布局支持(现在有一个错误,因此必须在目标上显式分配Authorization=""

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-12
    • 2018-09-12
    • 1970-01-01
    相关资源
    最近更新 更多