【发布时间】: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
我在 nlog 的 aspnet-request-ip 字段中有 2 个类似这种格式的 IP:
1.2.3.4, 1.1.1.1:2000
但我只想得到the first IP。我怎样才能做到这一点?
以上Ip是假的。
【问题讨论】:
标签: nlog
不太喜欢 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
【讨论】: