【问题标题】:How to split data in NLOG.config?如何拆分 NLOG.config 中的数据?
【发布时间】:2023-02-01 03:08:15
【问题描述】:

我在 nlog 的 aspnet-request-ip 字段中有 2 个类似这种格式的 IP:

 1.2.3.4, 1.1.1.1:2000

但我只想得到the first IP。我怎样才能做到这一点? 以上Ip是假的。

【问题讨论】:

    标签: nlog


    【解决方案1】:

    不太喜欢 RegEx,但这里有一个解决方案:

    ${replace:inner=${aspnet-request-ip}:regex=true:searchFor=,.*:replaceWith=}
    

    它扫描逗号,并用空白字符串替换逗号(以及逗号后的所有内容)。

    • "1.2.3.4, 1.1.1.1:2000"变成"1.2.3.4"
    • "1.2.3.4"变成"1.2.3.4"

    另见:https://github.com/NLog/NLog/wiki/Replace-Layout-Renderer

    【讨论】:

      猜你喜欢
      • 2018-01-18
      • 2011-03-19
      • 1970-01-01
      • 2021-11-30
      • 1970-01-01
      相关资源
      最近更新 更多