8000 Fix Sonar code smell (#751) · NLog/NLog.Extensions.Logging@e471ed5 · GitHub
[go: up one dir, main page]

Skip to content

Commit e471ed5

Browse files
authored
Fix Sonar code smell (#751)
1 parent 4547441 commit e471ed5

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/NLog.Extensions.Logging/Config/NLogLoggingConfiguration.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -348,18 +348,8 @@ private IEnumerable<IConfigurationSection> GetVariablesChildren(IConfigurationSe
348348
if (configValue is null)
349349
continue;
350350

351-
var independentVariable = true;
352-
for (int j = sortVariables.Count - 1; j >= 0; j--)
353-
{
354-
var otherConfigKey = sortVariables[j].Key;
355-
var referenceVariable = $"${{{otherConfigKey}}}";
356-
if (configValue.IndexOf(referenceVariable, StringComparison.OrdinalIgnoreCase) >= 0)
357-
{
358-
independentVariable = false;
359-
break;
360-
}
361-
}
362-
if (independentVariable)
351+
bool usingOtherVariables = IsNLogConfigVariableValueUsingOthers(configValue, sortVariables);
352+
if (!usingOtherVariables)
363353
{
364354
foundIndependentVariable = true;
365355
yield return sortVariables[i].Value;
@@ -378,6 +368,21 @@ private IEnumerable<IConfigurationSection> GetVariablesChildren(IConfigurationSe
378368
}
379369
}
380370

371+
private static bool IsNLogConfigVariableValueUsingOthers(string variableValue, List<KeyValuePair<string, IConfigurationSection>> allVariables)
372+
{
373+
foreach (var otherConfigVariable in allVariables)
374+
{
375+
var otherConfigKey = otherConfigVariable.Key;
376+
var referenceVariable = $"${{{otherConfigKey}}}";
377+
if (variableValue.IndexOf(referenceVariable, StringComparison.OrdinalIgnoreCase) >= 0)
378+
{
379+
return true;
380+
}
381+
}
382+
383+
return false;
384+
}
385+
381386
private static string GetConfigKey(IConfigurationSection child)
382387
{
383388
return child.Key?.Trim() ?? string.Empty;

0 commit comments

Comments
 (0)
0