Skip to content

Commit dfff5da

Browse files
authored
MicrosoftConsoleLayoutRenderer - Apply Span for EventId (#827)
1 parent 466f102 commit dfff5da

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/NLog.Extensions.Logging/LayoutRenderers/MicrosoftConsoleLayoutRenderer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ namespace NLog.Extensions.Logging
1313
[ThreadAgnostic]
1414
class MicrosoftConsoleLayoutRenderer : LayoutRenderer
1515
{
16+
#if NETFRAMEWORK
1617
private static readonly string[] EventIdMapper = Enumerable.Range(0, 512).Select(id => id.ToString(System.Globalization.CultureInfo.InvariantCulture)).ToArray();
18+
#endif
1719

1820
/// <summary>
1921
/// Gets or sets format string used to format timestamp in logging messages. Defaults to <c>null</c>.
@@ -65,11 +67,13 @@ protected override void Append(StringBuilder builder, LogEventInfo logEvent)
6567

6668
private static void AppendEventId(int eventId, StringBuilder builder)
6769
{
70+
#if NETFRAMEWORK
6871
if (eventId == 0)
6972
builder.Append('0');
7073
else if (eventId > 0 && eventId < EventIdMapper.Length)
7174
builder.Append(EventIdMapper[eventId]);
7275
else
76+
#endif
7377
builder.Append(eventId); // .NET5 (and newer) can append integer without string-allocation (using span)
7478
}
7579

0 commit comments

Comments
 (0)