0

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

2 Answers2

0

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.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
0

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.

Ramon Smits
  • 2,482
  • 1
  • 18
  • 20