Skip to content

Commit c44e5ec

Browse files
committed
Perf improvement
1 parent ec85412 commit c44e5ec

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Serilog.Sinks.OpenTelemetry/Sinks/OpenTelemetry/LogRecordBuilder.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,19 @@ public static LogRecord ToLogRecord(LogEvent logEvent, IFormatProvider? formatPr
3838

3939
public static void ProcessMessage(LogRecord logRecord, LogEvent logEvent, IncludedData includedFields, IFormatProvider? formatProvider)
4040
{
41-
var renderedMessage = CleanMessageTemplateFormatter.Format(logEvent.MessageTemplate, logEvent.Properties, formatProvider);
42-
43-
if (!includedFields.HasFlag(IncludedData.TemplateBody) && renderedMessage.Trim() != "")
41+
if (!includedFields.HasFlag(IncludedData.TemplateBody))
4442
{
45-
logRecord.Body = new AnyValue
43+
var renderedMessage = CleanMessageTemplateFormatter.Format(logEvent.MessageTemplate, logEvent.Properties, formatProvider);
44+
45+
if (renderedMessage.Trim() != "")
4646
{
47-
StringValue = renderedMessage
48-
};
47+
logRecord.Body = new AnyValue
48+
{
49+
StringValue = renderedMessage
50+
};
51+
}
4952
}
50-
51-
if (includedFields.HasFlag(IncludedData.TemplateBody) && logEvent.MessageTemplate.Text.Trim() != "")
53+
else if (includedFields.HasFlag(IncludedData.TemplateBody) && logEvent.MessageTemplate.Text.Trim() != "")
5254
{
5355
logRecord.Body = new AnyValue
5456
{

0 commit comments

Comments
 (0)