36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
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.
|
|
|
|
/// <summary>
|
|
/// Adds timestamp in multiple formats
|
|
/// </summary>
|
|
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;
|
|
}
|
|
} |