I have a class like so:
public class LoggedFoo
{
private readonly ILog _logger;
public LoggedFoo(ILog logger)
{
this._logger = logger;
}
public DoStuff()
{
this._logger.Info(i => i("Doing stuff..."));
}
}
One of the business requirements is that logs are being generated for certain functions, so naturally I want to mock out the ILog
to verify.
However, Common.Logging library supports type-based loggers, along the lines of:
var logger = LogManager.GetLogger<LoggedFoo>();
...or:
var logger = LogManager.GetLogger(typeof(LoggedFoo));
The problem is, we are using AutoFac for dependency injection, and I cannot figure out how to instantiate an ILog
based upon the class that is being instantiated for injection.
How do I write this? I am using the latest Nuget version of AutoFac.