diff --git a/src/NLog.Extensions.Logging/Logging/NLogLogger.cs b/src/NLog.Extensions.Logging/Logging/NLogLogger.cs index 32fdfee8..dc65fb10 100644 --- a/src/NLog.Extensions.Logging/Logging/NLogLogger.cs +++ b/src/NLog.Extensions.Logging/Logging/NLogLogger.cs @@ -174,12 +174,13 @@ private static void CaptureLogEventInfoParameters(LogEventInfo logEvent, NLogMes /// true if correct private static bool AllParameterCorrectlyPositionalMapped(NLogMessageParameterList messageParameters, MessageTemplateParameters messageTemplateParameters) { - if (messageTemplateParameters.Count != messageParameters.Count) + var messageParameterCount = messageParameters.Count; + if (messageParameterCount != messageTemplateParameters.Count) { return false; } - for (int i = 0; i < messageTemplateParameters.Count; ++i) + for (int i = 0; i < messageParameterCount; ++i) { if (!messageParameters[i].Name.Equals(messageTemplateParameters[i].Name, StringComparison.Ordinal)) {