Skip to content

Commit

Permalink
Use correct legacy NLogConfigurationException constructor to avoid is…
Browse files Browse the repository at this point in the history
…sue with string.Format parsing (#4806)
  • Loading branch information
snakefoot committed Feb 24, 2022
1 parent 7b0baf9 commit c42acda
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/NLog/Config/LoggingConfigurationElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static void AssertName(this ILoggingConfigurationElement section, params
}
catch (Exception exception)
{
var configException = new NLogConfigurationException(exception, $"'{attributeName}' hasn't a valid boolean value '{value}'. {defaultValue} will be used");
var configException = new NLogConfigurationException($"'{attributeName}' hasn't a valid boolean value '{value}'. {defaultValue} will be used", exception);
if (configException.MustBeRethrown())
{
throw configException;
Expand Down
7 changes: 3 additions & 4 deletions src/NLog/Config/LoggingConfigurationParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,8 @@ private LogLevel ParseLogLevelSafe(string attributeName, string attributeValue,
if (exception.MustBeRethrownImmediately())
throw;

const string message = "attribute '{0}': '{1}' isn't valid LogLevel. {2} will be used.";
var configException =
new NLogConfigurationException(exception, message, attributeName, attributeValue, @default);
new NLogConfigurationException($"attribute '{attributeName}': '{attributeValue}' isn't valid LogLevel. {@default} will be used.", exception);
if (MustThrowConfigException(configException))
throw configException;

Expand Down Expand Up @@ -1058,7 +1057,7 @@ private void ConfigureObjectFromAttributes(object targetObject, ILoggingConfigur
if (ex.MustBeRethrownImmediately())
throw;

var configException = new NLogConfigurationException(ex, $"Error when setting value '{childValue}' for property '{childName}' on element '{element}'");
var configException = new NLogConfigurationException($"Error when setting value '{childValue}' for property '{childName}' on element '{element}'", ex);
if (MustThrowConfigException(configException))
throw;
}
Expand Down Expand Up @@ -1291,7 +1290,7 @@ private bool ParseBooleanValue(string propertyName, string value, bool defaultVa
if (exception.MustBeRethrownImmediately())
throw;

var configException = new NLogConfigurationException(exception, $"'{propertyName}' hasn't a valid boolean value '{value}'. {defaultValue} will be used");
var configException = new NLogConfigurationException($"'{propertyName}' hasn't a valid boolean value '{value}'. {defaultValue} will be used", exception);
if (MustThrowConfigException(configException))
throw configException;
return defaultValue;
Expand Down

0 comments on commit c42acda

Please sign in to comment.