I've created a utility class that expects a logger to be passed at a method level, since I prefer legitimate errors to be written out for troubleshooting later on. Another developer hates passing the logger to the method, because he does not care.
- Cannot use optional attribute, since
ILogger
is not a constant. - Cannot use
params
because it would be a singleton, not a collection.
So I implemented it in the following manner:
public static class EmbeddedResourceUtility
{
public static string GetSqlQuery(string namespaceAndFileNameWithExtension, ILogger logger)
{
try
{
using(var stream = typeof(EmbeddedResourceUtility).GetTypeInfo().Assembly.GetManifestResourceStream(namespaceAndFileNameWithExtension))
using(var reader = new StreamReader(stream, Encoding.UTF8))
return reader.ReadToEnd();
}
catch(Exception exception)
{
logger.Error($"Failed to read query file {namespaceAndFileNameWithExtension}. {Environment.NewLine}{exception.HResult}: {exception.Message}");
throw new Exception(exception.Message);
}
}
}
Would be incorrect to expect someone to pass an ILogger even if they do not intend to use it? Or would there be a better way to handle this?