Skip to content

Commit

Permalink
Use the timestamp of the original log event
Browse files Browse the repository at this point in the history
Fixes the issue that log messages of one batch all get the time of preparing the batch as timestamps. Now the timestamp that comes with the Serilog log event is used.
  • Loading branch information
Mathias Koch committed Jul 3, 2020
1 parent 2997661 commit 590e3d4
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/Serilog.Sinks.Loki/LokiBatchFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public void Format(IEnumerable<LogEvent> logEvents, ITextFormatter formatter, Te
// We also remove backslashes and replace with forward slashes, Loki doesn't like those either
stream.Labels.Add(new LokiLabel(property.Key, property.Value.ToString().Replace("\"", "").Replace("\r\n", "\n").Replace("\\", "/")));

var localTime = DateTime.Now;
var localTimeAndOffset = new DateTimeOffset(localTime, TimeZoneInfo.Local.GetUtcOffset(localTime));
var time = localTimeAndOffset.ToString("o");
var time = logEvent.Timestamp.ToString("o");

var sb = new StringBuilder();
sb.AppendLine(logEvent.RenderMessage());
Expand Down

0 comments on commit 590e3d4

Please sign in to comment.