Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/NLog.Extensions.Logging/Config/NLogLoggingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,8 @@ private IEnumerable<IConfigurationSection> GetVariablesChildren(IConfigurationSe
if (configValue is null)
continue;

var independentVariable = true;
for (int j = sortVariables.Count - 1; j >= 0; j--)
{
var otherConfigKey = sortVariables[j].Key;
var referenceVariable = $"${{{otherConfigKey}}}";
if (configValue.IndexOf(referenceVariable, StringComparison.OrdinalIgnoreCase) >= 0)
{
independentVariable = false;
break;
}
}
if (independentVariable)
bool usingOtherVariables = IsNLogConfigVariableValueUsingOthers(configValue, sortVariables);
if (!usingOtherVariables)
{
foundIndependentVariable = true;
yield return sortVariables[i].Value;
Expand All @@ -378,6 +368,21 @@ private IEnumerable<IConfigurationSection> GetVariablesChildren(IConfigurationSe
}
}

private static bool IsNLogConfigVariableValueUsingOthers(string variableValue, List<KeyValuePair<string, IConfigurationSection>> allVariables)
{
foreach (var otherConfigVariable in allVariables)
{
var otherConfigKey = otherConfigVariable.Key;
var referenceVariable = $"${{{otherConfigKey}}}";
if (variableValue.IndexOf(referenceVariable, StringComparison.OrdinalIgnoreCase) >= 0)
{
return true;
}
}

return false;
}

private static string GetConfigKey(IConfigurationSection child)
{
return child.Key?.Trim() ?? string.Empty;
Expand Down