Skip to content

Commit

Permalink
Avoid using DateTime - Switch to DateTimeOffset (dotnet#39916)
Browse files Browse the repository at this point in the history
  • Loading branch information
maryamariyan authored Jul 25, 2020
1 parent 90989b4 commit f3f23b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public override void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeP
var timestampFormat = FormatterOptions.TimestampFormat;
if (timestampFormat != null)
{
var dateTime = FormatterOptions.UseUtcTimestamp ? DateTime.UtcNow : DateTime.Now;
timestamp = dateTime.ToString(timestampFormat);
DateTimeOffset dateTimeOffset = FormatterOptions.UseUtcTimestamp ? DateTimeOffset.UtcNow : DateTimeOffset.Now;
timestamp = dateTimeOffset.ToString(timestampFormat);
}
writer.WriteString("Timestamp", timestamp);
writer.WriteNumber(nameof(logEntry.EventId), eventId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public override void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeP
string timestampFormat = FormatterOptions.TimestampFormat;
if (timestampFormat != null)
{
DateTime dateTime = GetCurrentDateTime();
timestamp = dateTime.ToString(timestampFormat);
DateTimeOffset dateTimeOffset = GetCurrentDateTime();
timestamp = dateTimeOffset.ToString(timestampFormat);
}
if (timestamp != null)
{
Expand Down Expand Up @@ -126,9 +126,9 @@ static void WriteReplacing(TextWriter writer, string oldValue, string newValue,
}
}

private DateTime GetCurrentDateTime()
private DateTimeOffset GetCurrentDateTime()
{
return FormatterOptions.UseUtcTimestamp ? DateTime.UtcNow : DateTime.Now;
return FormatterOptions.UseUtcTimestamp ? DateTimeOffset.UtcNow : DateTimeOffset.Now;
}

private static string GetLogLevelString(LogLevel logLevel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public override void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeP
string timestampFormat = FormatterOptions.TimestampFormat;
if (timestampFormat != null)
{
DateTime dateTime = GetCurrentDateTime();
textWriter.Write(dateTime.ToString(timestampFormat));
DateTimeOffset dateTimeOffset = GetCurrentDateTime();
textWriter.Write(dateTimeOffset.ToString(timestampFormat));
}

// category and event id
Expand Down Expand Up @@ -96,9 +96,9 @@ static void WriteReplacingNewLine(TextWriter writer, string message)
}
}

private DateTime GetCurrentDateTime()
private DateTimeOffset GetCurrentDateTime()
{
return FormatterOptions.UseUtcTimestamp ? DateTime.UtcNow : DateTime.Now;
return FormatterOptions.UseUtcTimestamp ? DateTimeOffset.UtcNow : DateTimeOffset.Now;
}

private static string GetSyslogSeverityString(LogLevel logLevel)
Expand Down

0 comments on commit f3f23b4

Please sign in to comment.