Skip to content

RotatingStreamWriter: uses DateTime.Now instead of UTC for rotation date tracking #202

@Christophe-Rogiers

Description

@Christophe-Rogiers

Bug Description

Log rotation date tracking uses DateTime.Now (local time) instead of DateTime.UtcNow. Daylight saving time transitions can cause a 1-hour jump forward or backward, potentially triggering an unexpected rotation or skipping one.

Location

File: src/Servy.Core/IO/RotatingStreamWriter.cs
Line: 71

Code

_lastRotationDate = File.Exists(path) ? File.GetLastWriteTime(path) : DateTime.Now;

Also used in ShouldRotateByDate() and Rotate() methods with DateTime.Now.

Impact

During DST transitions:

  • Spring forward: logs may rotate 1 hour early
  • Fall back: logs may skip a rotation or create a duplicate rotation window

Suggested Fix

Use DateTime.UtcNow and File.GetLastWriteTimeUtc() consistently for rotation tracking:

_lastRotationDate = File.Exists(path) ? File.GetLastWriteTimeUtc(path) : DateTime.UtcNow;

Severity

Warning

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions