We are using the Microsoft.Extensions.Logging ILogging interface in our ASP.NET Core Web API which is exposing the two methods below:
LogError(ILogger, Exception, String, Object[])
LogError(ILogger, String, Object[])
When handling exception in our code we do our best to log them and the interface above will allow both method calls below to compile fine:
Logger.LogError(e, "Error message...")
Logger.LogError("Error message...", e) // bad call, will not log full exception info!
However, only the first method is the one that correctly logs exceptions, including the stack trace information. Going through our code base found that many LogError calls with exception were wrong.
So, my question is is there some kind of compilation option or some static checking tool to give us a warning or error when best argument match is not used for the method call? Obviously, first method is better matching for Exception type argument, but you can easily miss that when typing.