Skip to content

Commit ccf4dc8

Browse files
committed
Improve SelfLog when a configuration method is not found
List candidate methods only if there are any. Discovered this weird log while working on #353: > Unable to find a method called WithThreadName. Candidate methods are:
1 parent 79ecfe6 commit ccf4dc8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,17 +470,24 @@ static bool HasImplicitValueWhenNotSpecified(ParameterInfo paramInfo)
470470
.ToList();
471471

472472
if (!methodsByName.Any())
473-
SelfLog.WriteLine($"Unable to find a method called {name}. Candidate methods are:{Environment.NewLine}{string.Join(Environment.NewLine, candidateMethods)}");
473+
{
474+
SelfLog.WriteLine($"Unable to find a method called {name}.");
475+
if (candidateMethods.Any())
476+
{
477+
SelfLog.WriteLine($"Candidate methods are:{Environment.NewLine}{string.Join(Environment.NewLine, candidateMethods)}");
478+
}
479+
}
474480
else
481+
{
475482
SelfLog.WriteLine($"Unable to find a method called {name} "
476483
+ (suppliedArgumentNames.Any()
477484
? "for supplied arguments: " + string.Join(", ", suppliedArgumentNames)
478485
: "with no supplied arguments")
479486
+ ". Candidate methods are:"
480487
+ Environment.NewLine
481488
+ string.Join(Environment.NewLine, methodsByName));
489+
}
482490
}
483-
484491
return selectedMethod;
485492
}
486493

0 commit comments

Comments
 (0)