Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Taillefer (from Dev Box) committed Jul 17, 2024
1 parent 71df064 commit afb13cd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public void LogRecords(IEnumerable<BufferedLogRecord> records)

StringWriter writer = t_stringWriter ??= new StringWriter();

var sb = writer.GetStringBuilder();
foreach (var rec in records)
{
var logEntry = new LogEntry<BufferedLogRecord>(rec.LogLevel, _name, rec.EventId, rec, null, static (s, _) => s.FormattedMessage ?? string.Empty);
Formatter.Write(in logEntry, null, writer);

var sb = writer.GetStringBuilder();
if (sb.Length == 0)
{
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public override void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeP
return;
}

DateTimeOffset stamp = FormatterOptions.UseUtcTimestamp ? DateTimeOffset.UtcNow : DateTimeOffset.Now;
DateTimeOffset stamp = FormatterOptions.TimestampFormat != null
? (FormatterOptions.UseUtcTimestamp ? DateTimeOffset.UtcNow : DateTimeOffset.Now)
: DateTimeOffset.MinValue;

// We extract most of the work into a non-generic method to save code size. If this was left in the generic
// method, we'd get generic specialization for all TState parameters, but that's unnecessary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ static void WriteReplacing(TextWriter writer, string oldValue, string newValue,

private DateTimeOffset GetCurrentDateTime()
{
return FormatterOptions.UseUtcTimestamp ? DateTimeOffset.UtcNow : DateTimeOffset.Now;
return FormatterOptions.TimestampFormat != null
? (FormatterOptions.UseUtcTimestamp ? DateTimeOffset.UtcNow : DateTimeOffset.Now)
: DateTimeOffset.MinValue;
}

private static string GetLogLevelString(LogLevel logLevel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ static void WriteReplacingNewLine(TextWriter writer, string message)

private DateTimeOffset GetCurrentDateTime()
{
return FormatterOptions.UseUtcTimestamp ? DateTimeOffset.UtcNow : DateTimeOffset.Now;
return FormatterOptions.TimestampFormat != null
? (FormatterOptions.UseUtcTimestamp ? DateTimeOffset.UtcNow : DateTimeOffset.Now)
: DateTimeOffset.MinValue;
}

private static string GetSyslogSeverityString(LogLevel logLevel)
Expand Down

0 comments on commit afb13cd

Please sign in to comment.