From ccf4dc832ac5e55cfdd175122448927c7acef221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Thu, 16 Mar 2023 09:09:50 +0100 Subject: [PATCH 1/2] 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: --- .../Settings/Configuration/ConfigurationReader.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs index d5a3a92..a2c71c5 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs @@ -470,8 +470,15 @@ static bool HasImplicitValueWhenNotSpecified(ParameterInfo paramInfo) .ToList(); if (!methodsByName.Any()) - SelfLog.WriteLine($"Unable to find a method called {name}. Candidate methods are:{Environment.NewLine}{string.Join(Environment.NewLine, candidateMethods)}"); + { + SelfLog.WriteLine($"Unable to find a method called {name}."); + if (candidateMethods.Any()) + { + SelfLog.WriteLine($"Candidate methods are:{Environment.NewLine}{string.Join(Environment.NewLine, candidateMethods)}"); + } + } else + { SelfLog.WriteLine($"Unable to find a method called {name} " + (suppliedArgumentNames.Any() ? "for supplied arguments: " + string.Join(", ", suppliedArgumentNames) @@ -479,8 +486,8 @@ static bool HasImplicitValueWhenNotSpecified(ParameterInfo paramInfo) + ". Candidate methods are:" + Environment.NewLine + string.Join(Environment.NewLine, methodsByName)); + } } - return selectedMethod; } From 4ab71a97bc35e5184f0c02ff0d07fbb6d7faf677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Fri, 17 Mar 2023 08:32:33 +0100 Subject: [PATCH 2/2] Update src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs Co-authored-by: Ivan Maximov --- .../Settings/Configuration/ConfigurationReader.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs index a2c71c5..7dd5b9b 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs @@ -471,10 +471,13 @@ static bool HasImplicitValueWhenNotSpecified(ParameterInfo paramInfo) if (!methodsByName.Any()) { - SelfLog.WriteLine($"Unable to find a method called {name}."); if (candidateMethods.Any()) { - SelfLog.WriteLine($"Candidate methods are:{Environment.NewLine}{string.Join(Environment.NewLine, candidateMethods)}"); + SelfLog.WriteLine($"Unable to find a method called {name}. Candidate methods are:{Environment.NewLine}{string.Join(Environment.NewLine, candidateMethods)}"); + } + else + { + SelfLog.WriteLine($"Unable to find a method called {name}. No candidates found."); } } else