kibana - 为什么我会从 NLog FileTarget 在 Kibana 中获得部分日志消息?
问题描述
我正在使用 NLog FileTarget 将消息记录在一个文件中,该文件被 filebeat 拾取以发送到 Kibana。
我的消息通常是多行的。
我注意到一些消息显示在 Kibana 中,多行消息中只有一些行。
例如,在 logfie 我有这样的东西
2020-05-04 16:23:16.1523|::1|80000037-0000-fb00-b63f-84710c7967bb
2020-05-04 16:23:16.1523|::1|80000037-0000-fb00-b63f-84710c7967bb||INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request starting HTTP/2.0 GET https://localhost:44328/Foo
2020-05-04 16:23:16.2287|::1|80000037-0000-fb00-b63f-84710c7967bb|user1|DEBUG|MyApp.Web.Controllers.FooController|Validation OK
2020-05-04 16:23:16.2530|::1|80000037-0000-fb00-b63f-84710c7967bb|user1|DEBUG|MyApp.Web.BusinessLogic.FooLogic|Query results time:3ms
2020-05-04 16:23:16.2687|::1|80000037-0000-fb00-b63f-84710c7967bb|user1|DEBUG|MyApp.Web.BusinessLogic.FooLogic|Count:0 time:1ms
2020-05-04 16:23:16.6127|::1|80000037-0000-fb00-b63f-84710c7967bb|user1|INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request finished in 459.4438ms 200 text/html; charset=utf-8
但在 kibana 我只看到
2020-05-04 16:23:16.1523|::1|80000037-0000-fb00-b63f-84710c7967bb
2020-05-04 16:23:16.1523|::1|80000037-0000-fb00-b63f-84710c7967bb||INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request starting HTTP/2.0 GET https://localhost:44328/Foo
2020-05-04 16:23:16.2287|::1|80000037-0000-fb00-b63f-84710c7967bb|user1|DEBUG|MyApp.Web.Controllers.FooController|Validation OK
2020-05-04 16:23:16.2530|::1|80000037-0000-fb00-b63f-84710c7967bb|user1|DEBUG|MyApp.Web.BusinessLogic.FooLogic|Query results time:3ms
请注意,这只发生在某些消息上,而不是全部,并且日志消息的大小似乎并不重要。我已经记录了很长的消息,而较小的消息被裁剪了。
我能想到的唯一原因是消息不是一口气写的,而是分部分写的,kibana 选择了部分消息而忽略了其余部分。是这样吗?如果是这样,我可以将目标配置为一次全部写入消息吗?
我的堆栈是:
- .NET 核心 3.1
- C#
- NLog 4.7.0
- NLog.Web.AspNetCore 4.9.2
我的文件目标配置如下所示:
"target": {
"type": "File",
"fileName": "c:\\wwwlogs\\MyApp.Web\\Combined.log",
"archiveFileName": "c:\\wwwlogs\\MyApp.Web\\archives\\Combined.{#}.log",
"archiveEvery": "Day",
"archiveNumbering": "Rolling",
"maxArchiveFiles": "7",
"layout": "${longdate}|${aspnet-request-ip}|${aspnet-TraceIdentifier}|${aspnet-user-identity}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}"
}
FileBeat 配置为:
- type: log
enabled: true
paths:
- C:\wwwlogs\MyApp.Web\Combined.log
multiline.pattern: '^[[:space:]]'
multiline.negate: false
multiline.match: after
解决方案
尴尬,但事实证明这不是问题。整个消息被 filebeat 拾取,但仅部分显示在 Kibana 索引视图上。如果单击消息详细信息,则可以看到整条消息。
所以,NLog 和 filebeat 没问题,这是 Kibana 中的视图问题
推荐阅读
- python-3.x - 可散列类型:if 语句中的列表错误
- python - 在 Python 中处理二进制文件时使用什么合适的迭代器?
- python - 需要使用 Contour 检测图像的第二个极值点
- java - 对象列为空?
- python-3.x - 遇到以下问题:Eager Mode 不支持 build_tensor_flow
- sql - 如何将 WordPress 自定义帖子和类别更改为新的自定义帖子和类别
- flutter - 显示通知的最简单方法
- c++ - C ++枚举到模板化函数
- javascript - 如何添加一个窗口事件侦听器(在功能组件内),该侦听器回调作为道具接收的函数
- python - python列表理解不适用于list.extend