8000 NLogMessageParameterList - Optimize index operator to skip paramater-… · NLog/NLog.Extensions.Logging@43f65f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 43f65f3

Browse files
committed
NLogMessageParameterList - Optimize index operator to skip paramater-name validation when no message template capture
1 parent 0506213 commit 43f65f3

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

examples/NetCore2/HostingExample/HostingExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
18+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

src/NLog.Extensions.Logging/Logging/NLogMessageParameterList.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ private static bool IsValidParameterList(IReadOnlyList<KeyValuePair<string, obje
9797
string parameterName;
9898

9999
var parameterCount = parameterList.Count;
100-
101100
for (int i = 0; i < parameterCount; ++i)
102101
{
103102
if (!TryGetParameterName(parameterList, i, out parameterName))
@@ -188,15 +187,21 @@ public MessageTemplateParameter this[int index]
188187
index += 1;
189188

190189
var parameter = _parameterList[index];
191-
var parameterName = parameter.Key;
192-
var capture = GetCaptureType(parameterName[0]);
193-
if (capture != CaptureType.Normal)
194-
parameterName = parameterName.Substring(1);
195-
return new MessageTemplateParameter(parameterName, parameter.Value, null, capture);
190+
return _hasMessageTemplateCapture ?
191+
GetMessageTemplateParameter(parameter.Key, parameter.Value) :
192+
new MessageTemplateParameter(parameter.Key, parameter.Value, null, CaptureType.Normal);
196193
}
197194
set => throw new NotSupportedException();
198195
}
199196

197+
private static MessageTemplateParameter GetMessageTemplateParameter(string parameterName, object parameterValue)
198+
{
199+
var capture = GetCaptureType(parameterName[0]);
200+
if (capture != CaptureType.Normal)
201+
parameterName = parameterName.Substring(1);
202+
return new MessageTemplateParameter(parameterName, parameterValue, null, capture);
203+
}
204+
200205
private static CaptureType GetCaptureType(char firstChar)
201206
{
202207
if (firstChar == '@')

0 commit comments

Comments
 (0)
0