using EonaCat.LogStack.Core; using System; using System.Diagnostics; using System.Runtime.CompilerServices; namespace EonaCat.LogStack.Boosters; // This file is part of the EonaCat project(s) which is released under the Apache License. // See the LICENSE file or go to https://EonaCat.com/License for full license details. /// /// Adds timestamp in multiple formats /// public sealed class TimestampBooster : BoosterBase { private readonly TimestampMode _mode; public TimestampBooster(TimestampMode mode = TimestampMode.Utc) : base("Timestamp") { _mode = mode; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Boost(ref LogEventBuilder builder) { var timestamp = _mode switch { TimestampMode.Local => DateTime.Now.Ticks, TimestampMode.HighPrecision => Stopwatch.GetTimestamp(), _ => DateTime.UtcNow.Ticks }; builder.WithTimestamp(timestamp); return true; } }