LocalTimestampEnricher.cs
554 Bytes
using Serilog.Core;
using Serilog.Events;
namespace Rcs.Api.Logging;
public sealed class LocalTimestampEnricher(TimeZoneInfo timeZone) : ILogEventEnricher
{
private readonly TimeZoneInfo _timeZone = timeZone;
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var localTimestamp = TimeZoneInfo.ConvertTime(DateTimeOffset.Now, _timeZone)
.ToString("yyyy-MM-dd HH:mm:ss.fff");
logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("LocalTimestamp", localTimestamp));
}
}