class LogUtil<T> : ILogUtility
{
log4net.ILog log;
public LogUtil()
{
log = log4net.LogManager.GetLogger(typeof(T).FullName);
}
public void Log(LogType logtype, string message)
{
Console.WriteLine("logging coming from class {0} - message {1} " , typeof(T).FullName, message);
}
}
public class Logger
{
ILogUtility _logutility;
public Logger(ILogUtility logutility)
{
_logutility = logutility;
}
public void Log(LogType logtype, string message)
{
_logutility.Log(logtype, message);
}
}
I need to have the functionality to be flexible and have the ability to remove the LogUtil class in the future and use some thing else.
So I write LoggerUtility wrapper class as follows:
class LoggerUtility<T>
{
public Logger logger
{
get
{
LogUtil<T> logutil = new LogUtil<T>();
Logger log = new Logger(logutil);
return log;
}
}
}
My client code as follows:
public class TestCode
{
public void test()
{
new LoggerUtility<TestCode>().logger.Log(LogType.Info, "hello world");
}
}
I am coding Logger property which may not be clean.
as you can see that following line does not look clean.
new LoggerUtility<TestCode>().logger.Log(LogType.Info, "hello world");
Is there a better way to write the client code? I want to have loose coupling with LogUtil and not use it directly in my client code.
Please let me know.
Thanks