Skip to content

Commit 3c6ca69

Browse files
committed
Optimization: used StartsWith(char) instead of StartsWith(string) where supported
1 parent 1e9f655 commit 3c6ca69

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,20 @@ LogEvent PrepareWrite<TState>(LogEventLevel level, EventId eventId, TState state
103103
{
104104
messageTemplate = value;
105105
}
106+
#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
107+
else if (property.Key.StartsWith('@'))
108+
#else
106109
else if (property.Key.StartsWith("@"))
110+
#endif
107111
{
108112
if (_logger.BindProperty(GetKeyWithoutFirstSymbol(DestructureDictionary, property.Key), property.Value, true, out var destructured))
109113
properties.Add(destructured);
110114
}
115+
#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
116+
else if (property.Key.StartsWith('$'))
117+
#else
111118
else if (property.Key.StartsWith("$"))
119+
#endif
112120
{
113121
if (_logger.BindProperty(GetKeyWithoutFirstSymbol(StringifyDictionary, property.Key), property.Value?.ToString(), true, out var stringified))
114122
properties.Add(stringified);

src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerScope.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,20 @@ public static void EnrichWithStateAndCreateScopeItem(LogEvent logEvent, ILogEven
5454
void AddProperty(string key, object? value)
5555
{
5656
var destructureObject = false;
57-
57+
#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
58+
if (key.StartsWith('@'))
59+
#else
5860
if (key.StartsWith("@"))
61+
#endif
5962
{
6063
key = SerilogLogger.GetKeyWithoutFirstSymbol(SerilogLogger.DestructureDictionary, key);
6164
destructureObject = true;
6265
}
66+
#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
67+
else if (key.StartsWith('$'))
68+
#else
6369
else if (key.StartsWith("$"))
70+
#endif
6471
{
6572
key = SerilogLogger.GetKeyWithoutFirstSymbol(SerilogLogger.StringifyDictionary, key);
6673
value = value?.ToString();

0 commit comments

Comments
 (0)