Say I have an interface, for example:
public interface ILoggable
{
void Log(Func<string> message, Logger.Type type);
}
And some extension methods, for example:
public static class Logger
{
public static void Log(this ILoggable loggable, Func<string> message) { loggable.Log(message, Type.Information); }
public static void Log(this ILoggable loggable, string prefix, byte[] data, int len) { }
public static void Log(this ILoggable loggable, Exception ex) { }
}
Then, in any class CoreService : ServiceBase, ILoggableor such, I implement this public void Log(Func<string> message, Logger.Type type)for what I like (the public modifier is kind of meh ...) and uses all the extension methods for actually logging.
Still so good ... or not so good? Is there something wrong with this approach? If not, then why the inconvenience:
catch (Exception ex) {
this.Log(ex); // this works
Log(ex); // this goes not
source
share