Skip to content

[Code Quality] Logger.cs — Log timestamp lacks UTC/local indicator, ambiguous when UseLocalTimeForRotation is enabled #842

@Christophe-Rogiers

Description

@Christophe-Rogiers

Severity: Info

File: src/Servy.Core/Logging/Logger.cs
Lines: 314-315

Description:
The log entry timestamp is formatted as [yyyy-MM-dd HH:mm:ss] and silently switches between DateTime.UtcNow and DateTime.Now based on _useLocalTimeForRotation:

var now = _useLocalTimeForRotation ? DateTime.Now : DateTime.UtcNow;
string logEntry = $"[{now:yyyy-MM-dd HH:mm:ss}] [{levelName}] {sanitizedMessage}";

There is no marker (Z, UTC, local TZ name/offset) in the formatted output. An operator looking at a Servy.Service.log cannot tell whether the timestamps are UTC or local. On machines that span multiple regions (or where Servy runs in mixed environments), correlating logs across hosts becomes guesswork.

This contradicts the SetUseLocalTimeForRotation doc, which describes the choice as having forensic implications. The same _useLocalTimeForRotation flag also drives LoggerInitializationErrors.log line 120-123 with the same omission.

Suggested fix:
Append a UTC Z suffix when UTC is in effect, or append the local offset (e.g. +02:00) when local is in effect. ISO-8601 round-trip (o) is overkill, but a minimal disambiguator like:

string tzMarker = _useLocalTimeForRotation ? now.ToString("zzz") : "Z";
string logEntry = $"[{now:yyyy-MM-dd HH:mm:ss}{tzMarker}] [{levelName}] {sanitizedMessage}";

would make the timestamp self-describing.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions