Skip to content

Commit

Permalink
NLogLoggingConfiguration - Add support for config variables with Json…
Browse files Browse the repository at this point in the history
…Layout
  • Loading branch information
snakefoot committed Jan 6, 2021
1 parent 6defbc2 commit f45c654
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/NLog.Extensions.Logging/Config/NLogLoggingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,6 @@ public LoggingConfigurationElement(IConfigurationSection configurationSection, b

private IEnumerable<KeyValuePair<string, string>> GetValues()
{
var children = _configurationSection.GetChildren();
foreach (var child in children)
{
if (!child.GetChildren().Any())
{
yield return new KeyValuePair<string, string>(GetConfigKey(child), child.Value);
}
}

if (_nameOverride != null)
{
if (ReferenceEquals(_nameOverride, DefaultTargetParameters))
Expand All @@ -179,7 +170,20 @@ private IEnumerable<KeyValuePair<string, string>> GetValues()

if (ReferenceEquals(_nameOverride, VariableKey))
{
yield return new KeyValuePair<string, string>("value", _configurationSection.Value);
var value = _configurationSection.Value;
if (value != null)
yield return new KeyValuePair<string, string>("value", value);
else
yield break; // Signal to NLog Config Parser to check GetChildren() for variable layout
}
}

var children = _configurationSection.GetChildren();
foreach (var child in children)
{
if (!child.GetChildren().Any())
{
yield return new KeyValuePair<string, string>(GetConfigKey(child), child.Value);
}
}
}
Expand All @@ -204,10 +208,17 @@ private IEnumerable<ILoggingConfigurationElement> GetChildren()
}
}

var children = _configurationSection.GetChildren();
foreach (var loggingConfigurationElement in GetChildren(children, variables, isTargetsSection))
if (ReferenceEquals(_nameOverride, VariableKey) && _configurationSection.Value == null)
{
yield return new LoggingConfigurationElement(_configurationSection, false);
}
else
{
yield return loggingConfigurationElement;
var children = _configurationSection.GetChildren();
foreach (var loggingConfigurationElement in GetChildren(children, variables, isTargetsSection))
{
yield return loggingConfigurationElement;
}
}
}

Expand Down

0 comments on commit f45c654

Please sign in to comment.