@@ -160,15 +160,6 @@ public LoggingConfigurationElement(IConfigurationSection configurationSection, s
160160
161161 private IEnumerable < KeyValuePair < string , string > > GetValues ( )
162162 {
163- var children = _configurationSection . GetChildren ( ) ;
164- foreach ( var child in children )
165- {
166- if ( ! child . GetChildren ( ) . Any ( ) )
167- {
168- yield return new KeyValuePair < string , string > ( GetConfigKey ( child ) , child . Value ) ;
169- }
170- }
171-
172163 if ( _nameOverride != null )
173164 {
174165 if ( ReferenceEquals ( _nameOverride , DefaultTargetParameters ) )
@@ -182,7 +173,20 @@ private IEnumerable<KeyValuePair<string, string>> GetValues()
182173
183174 if ( ReferenceEquals ( _nameOverride , VariableKey ) )
184175 {
185- yield return new KeyValuePair < string , string > ( "value" , _configurationSection . Value ) ;
176+ var value = _configurationSection . Value ;
177+ if ( value != null )
178+ yield return new KeyValuePair < string , string > ( "value" , value ) ;
179+ else
180+ yield break ; // Signal to NLog Config Parser to check GetChildren() for variable layout
181+ }
182+ }
183+
184+ var children = _configurationSection . GetChildren ( ) ;
185+ foreach ( var child in children )
186+ {
187+ if ( ! child . GetChildren ( ) . Any ( ) )
188+ {
189+ yield return new KeyValuePair < string , string > ( GetConfigKey ( child ) , child . Value ) ;
186190 }
187191 }
188192 }
@@ -207,10 +211,17 @@ private IEnumerable<ILoggingConfigurationElement> GetChildren()
207211 }
208212 }
209213
210- var children = _configurationSection . GetChildren ( ) ;
211- foreach ( var loggingConfigurationElement in GetChildren ( children , variables , isTargetsSection ) )
214+ if ( ReferenceEquals ( _nameOverride , VariableKey ) && _configurationSection . Value == null )
215+ {
216+ yield return new LoggingConfigurationElement ( _configurationSection ) ;
217+ }
218+ else
212219 {
213- yield return loggingConfigurationElement ;
220+ var children = _configurationSection . GetChildren ( ) ;
221+ foreach ( var loggingConfigurationElement in GetChildren ( children , variables , isTargetsSection ) )
222+ {
223+ yield return loggingConfigurationElement ;
224+ }
214225 }
215226 }
216227
0 commit comments