以 UTC 时间格式而不是操作系统上设置的时间格式写入 nservicebus 日志

发布于 2025-01-17 11:43:03 字数 785 浏览 4 评论 0原文

当消息写入NSB日志(NSB_YY-MM-DD_X.TXT)中时,它们始终写在OS上设置的时区(在这种情况下为Windows 2019 Enterprise Box,Americas/New York)。示例下图:

2022-03-25 16:19:26.790 INFO接收到PloteDrord,OrderID 79308F8A-5FEF-49D0-BC86-C86-C886F57F57F1472

我可以更改NSB日志的唯一方法是以UTC形式编写日期/到UTC的操作系统上设置时间。我想知道的是,是否可以在UTC时间内编写NSB日志而不将OS日期/时间设置为UTC?我想将这些日志条目发送到Elasticsearch中,但是当时间戳通过时,它将时间戳视为UTC,当我在Kibana中查看它时,时间戳落后4小时。

我已经尝试了流利的其他方法和Fluentd中的其他方法来调整NSB日志的时间戳(fluent-bit中的lua脚本,将time_offset设置为fluent-bit,use_utc_timekey in Fluentd等),但无济于事。它不会将时间戳值调整为UTC。

我在nservicebus中的源代码中唯一看到的位置是DefaultLoggerfactory.cs文件,我看到时间戳的格式看起来与NSB日志相同。

谢谢。

  • 更改了NserviceBus应用程序中的Windows OS到UTC(这有效,但我不想这样做)
  • 使用fluent-Bit中的LUA脚本来调整日志输入中的时间戳值,
  • 添加了use_utc_timekeke设置为tre,以将日志输入发送到我的s3 buccet在流利

When messages get written into the nsb logs (nsb_yy-mm-dd_X.txt), they are always written in the time zone that's set on the OS (in this case on a Windows 2019 Enterprise box, Americas/New York). Sample Below:

2022-03-25 16:19:26.790 INFO Received PlaceOrder, OrderId 79308f8a-5fef-49d0-bc86-c886f57f1472

The only way I can change the nsb logs where the timestamp is written in UTC form is to configure the date/time setting on the OS to UTC. What I want to know is whether or not it's possible to write the NSB logs in UTC time WITHOUT setting the OS date/time to UTC? I want to send these log entries into ElasticSearch but when the timestamp is passed, it treats the timestamp as UTC and when I view it in Kibana, the timestamp is 4 hours behind.

I have tried other methods in fluent-bit and fluentd to adjust the timestamp off the NSB logs (lua script in fluent-bit, set Time_Offset in fluent-bit, use_utc_timekey in fluentd, etc) but to no avail. It doesn't adjust the timestamp value to UTC.

The only place I see in the source code in nservicebus is the DefaultLoggerFactory.cs file where I see the format of the timestamp that looks like the same as the nsb logs.

Thanks.

  • Changed Windows OS in nservicebus application to UTC (this works but I don't want to do this)
  • Used lua script in fluent-bit to adjust timestamp value in log entry
  • Added a use_utc_timekey set to true to send the log entry to my S3 bucket in fluentd

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

第几種人 2025-01-24 11:43:03

这是您需要使用日志记录库进行配置的东西。默认情况下,nservicebus使用了log4net,但同样的方法将适用于其他日志记录器。

您需要提供自定义对话模式。关注官方示例做到这一点。该模式需要使用%UTCDATE {ISO8601}而不是%D

您可以查看其他 log4net模式如果您喜欢根据需要调整日志。

This is something you'll need to configure with the logging library. By default, NServiceBus is using Log4Net but the same approach would apply to other loggers.

You'll need to provide a custom conversation pattern. Follow the official example to do exactly that. The pattern would need to use %utcdate{ISO8601} instead of %d.

You can review other Log4Net patterns if you'd like to adjust your logs as necessary.

远山浅 2025-01-24 11:43:03

NServiceBus by 默认使用一个非常简单的记录器(它不是 log4net)。

对于日志记录自定义,强烈建议通过 NServiceBus.Extensions.Hosting 或 NServiceBus.Extensions.Logging 包将 NServiceBus 配置为使用 Microsoft 日志记录扩展 (NServiceBus.Extensions.Logging)。

通过使用日志扩展,您可以使用流行的框架,如 SeriLog、NLog 或 Log4net。

还有一个名为 Elasticsearch.Extensions.Logging 的 ElasticSearch 包,您可以使用它可以用来直接登录ElasticSearch。

我建议添加和配置 NServiceBus.Extensions.Hosting 和 Elasticsearch.Extensions.Logging 包。

NServiceBus by default uses a very simple logger (it's not log4net).

For logging customization it is highly recommended to configure NServiceBus to use the Microsoft logging extensions (NServiceBus.Extensions.Logging) via either the NServiceBus.Extensions.Hosting or NServiceBus.Extensions.Logging package.

By using the logging extensions you can use popular frameworks like SeriLog, NLog or Log4net.

There is also a package for ElasticSearch called Elasticsearch.Extensions.Logging which you can use to directly log to ElasticSearch.

I recommend adding and configuring the NServiceBus.Extensions.Hosting and Elasticsearch.Extensions.Logging package.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文