Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/NLogPublic

Commitcbe7b3d

Browse files
committed
LoggingConfigurationParser - Report unrecognized options in targets and rules section
1 parent56727c0 commitcbe7b3d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

‎src/NLog/Config/LoggingConfigurationParser.cs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,16 @@ private void ParseRulesElement(ValidatedConfigurationElement rulesElement, IList
547547
rulesInsertPosition=rulesCollection.Count;
548548
}
549549

550+
if(rulesElement.Values.Count>0)
551+
{
552+
foreach(varrulesOptionsinrulesElement.Values)
553+
{
554+
varconfigException=newNLogConfigurationException($"Unrecognized value '{rulesOptions.Key}'='{rulesOptions.Value}' in section '{rulesElement.Name}'");
555+
if(MustThrowConfigException(configException))
556+
throwconfigException;
557+
}
558+
}
559+
550560
foreach(varchildIteminrulesElement.ValidChildren)
551561
{
552562
varloggingRule=ParseRuleElement(childItem);
@@ -843,6 +853,18 @@ private void ParseTargetsElement(ValidatedConfigurationElement targetsElement)
843853
targetsElement.AssertName("targets","appenders");
844854

845855
boolasyncWrap=ParseBooleanValue("async",targetsElement.GetOptionalValue("async","false")??string.Empty,false);
856+
if(targetsElement.Values.Count>(asyncWrap?1:0))
857+
{
858+
foreach(vartargetsOptionsintargetsElement.Values)
859+
{
860+
if(string.Equals(targetsOptions.Key?.Trim(),"async",StringComparison.OrdinalIgnoreCase))
861+
continue;
862+
863+
varconfigException=newNLogConfigurationException($"Unrecognized value '{targetsOptions.Key}'='{targetsOptions.Value}' in section '{targetsElement.Name}'");
864+
if(MustThrowConfigException(configException))
865+
throwconfigException;
866+
}
867+
}
846868

847869
ValidatedConfigurationElement?defaultWrapperElement=null;
848870
Dictionary<string,ValidatedConfigurationElement>?typeNameToDefaultTargetParameters=null;

‎tests/NLog.UnitTests/Config/XmlConfigTests.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ public void InvalidNLogAttributeValues_shouldNotBreakLogging()
201201
{
202202
// Arrange
203203
varxml=@"<nlog internalLogLevel='oops' globalThreshold='noooos'>
204-
<targets>
204+
<targets option='unknown'>
205205
<target name='debug' type='Debug' layout='${message}' />
206206
</targets>
207-
<rules>
207+
<rules bingo='tada'>
208208
<logger name='*' minlevel='debug' appendto='debug' />
209209
</rules>
210210
</nlog>";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp