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

LoggingConfigurationParser - Report unrecognized options in targets and rules section#6045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
snakefoot wants to merge1 commit intoNLog:dev
base:dev
Choose a base branch
Loading
fromsnakefoot:config_targets_validate
Open
Show file tree
Hide file tree
Changes fromall 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
22 changes: 22 additions & 0 deletionssrc/NLog/Config/LoggingConfigurationParser.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -547,6 +547,16 @@
rulesInsertPosition = rulesCollection.Count;
}

if (rulesElement.Values.Count > 0)
{
foreach (var rulesOption in rulesElement.Values)
{
var configException = new NLogConfigurationException($"Unrecognized value '{rulesOption.Key}'='{rulesOption.Value}' in section '{rulesElement.Name}'");
if (MustThrowConfigException(configException))
throw configException;
}
}

foreach (var childItem in rulesElement.ValidChildren)
{
var loggingRule = ParseRuleElement(childItem);
Expand DownExpand Up@@ -838,11 +848,23 @@
}
}

private void ParseTargetsElement(ValidatedConfigurationElement targetsElement)

Check failure on line 851 in src/NLog/Config/LoggingConfigurationParser.cs

View check run for this annotation

SonarQubeCloud/ SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 28 to the 20 allowed.

See more on https://sonarcloud.io/project/issues?id=nlog2&issues=AZqdUunQCnHg2yY8GF5V&open=AZqdUunQCnHg2yY8GF5V&pullRequest=6045
{
targetsElement.AssertName("targets", "appenders");

bool asyncWrap = ParseBooleanValue("async", targetsElement.GetOptionalValue("async", "false") ?? string.Empty, false);
if (targetsElement.Values.Count > (asyncWrap ? 1 : 0))
{
foreach (var targetsOption in targetsElement.Values)
{
if (string.Equals(targetsOption.Key?.Trim(), "async", StringComparison.OrdinalIgnoreCase))
continue;

var configException = new NLogConfigurationException($"Unrecognized value '{targetsOption.Key}'='{targetsOption.Value}' in section '{targetsElement.Name}'");
if (MustThrowConfigException(configException))
throw configException;
}
}

ValidatedConfigurationElement? defaultWrapperElement = null;
Dictionary<string, ValidatedConfigurationElement>? typeNameToDefaultTargetParameters = null;
Expand Down
6 changes: 3 additions & 3 deletionstests/NLog.UnitTests/Config/XmlConfigTests.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -201,18 +201,18 @@ public void InvalidNLogAttributeValues_shouldNotBreakLogging()
{
// Arrange
var xml = @"<nlog internalLogLevel='oops' globalThreshold='noooos'>
<targets>
<targets option='unknown'>
<target name='debug' type='Debug' layout='${message}' />
</targets>
<rules>
<rules bingo='tada'>
<logger name='*' minlevel='debug' appendto='debug' />
</rules>
</nlog>";

var logFactory = new LogFactory();
var config = XmlLoggingConfiguration.CreateFromXmlString(xml, logFactory);
logFactory.Configuration = config;
var logger = logFactory.GetLogger("InvalidInternalLogLevel_shouldNotBreakLogging");
var logger = logFactory.GetLogger("InvalidNLogAttributeValues_shouldNotBreakLogging");

// Act
logger.Debug("message 1");
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp