0 votes
ago by (210 points)

The SyslogMessage class had a Timestamp Member described as "Gets the timestamp part of the syslog message as supplied by the client. Only available for messages received by a syslog server."
The type of this member is DateTime? which means that it does not convey the the timezone offset element of the TIMESTAMP field of the message described in RFC5424 so a value of 1985-04-12T19:20:50.52-04:00 would lose information regarding the local time at point of generation.
Should the type not actually be a DateTimeOffset to allow this data to be passed out intact?

Applies to: Syslog

1 Answer

0 votes
ago by (76.2k points)
selected ago by
 
Best answer

Yes, you are right that information about local time zone of the originator is lost. We chose DateTime because it is a more common type and easier to use.

Details about TIMESTAMP parsing process:

  1. The 1985-04-12T19:20:50.52-04:00 is parsed as DateTime(date, 19:20:50.52) and the -04:00 time zone.
  2. The DateTime is transformed to UTC = DateTime(date, 23:20:50.52)
  3. The DateTime is transformed to machine's local time and stored in SyslogMessage.Timestamp.

So, if the server application simply "prints" the SyslogMessage.Timestamp of all receiving messages, they are all shown in the same (machine local) time zone and it is easily comparable to the clock on that machine as well as the SyslogMessageReceivedEventArgs.ReceivedTime value (which is also in machine local time).

If you need to know the original time zone, please leave a comment here with description of your use case. We will think about a way to provide this information (e.g. SyslogMessage.GetTimestampOffset() or something like that). However, please note that clients are not required to use the local time zone format. They can use UTC. Also please note that in previous version of the Syslog protocol (RFC 3164) the TIMESTAMP does not use time zones at all. So, you can end up in messages with an offset and messages without it.


The possible workaround to get the information is to parse the whole message for yourself. It can be done by using the SyslogMessageFormat.Plain like this:

var binding = new SyslogBinding(...){ Format = SyslogMessageFormat.Plain };
server.Bind(binding);

In this case, the server does not parse the message - the whole message data are accessible using the SyslogMessage.Text property.

Note: If you choose Legacy instead Plain format, only the <PRI> part of the Syslog message is parsed, the Facility and Severity properties are filled, the <PRI> value will not be part of the SyslogMessage.Text property.

ago by (210 points)
Hi Lukas
The use case that we have is many hardware devices spread across multiple timezones that send messages to a syslog server in a datacentre.
We want to be able to show the log of these events in chronological order displaying both the client browser's local time for the event and the source local time so that a user is able to make reference to the correct local time (if available) when conversing with somebody that is "on-site" investigating an event which on a local interface would be showing a different time to that of the user.  We are trying to take away as much as possible the need to know the location (and  timezone) of a device and the manual adjustment of time when conversing in local times rather than UTC
ago by (76.2k points)
Thank you for the info. We will think of an API to provide the missing information.
I will let you know here, when the API is available.
...