I am using ASP.NET Core, I know that such a logging mechanism is already provided by the framework, but using this to illustrate my problem.
I use the Factory template to create the Logger class, since I do not know the type of logging (because it is stored in the database).
ILogger Agreement
Log(string msg)
LoggerFactory will then return an ILogger after creating the Logger based on the parameter passed from the DB:
public class LoggerFactory
{
public static Contracts.ILogger BuildLogger(LogType type)
{
return GetLogger(type);
}
Now that I need to use Logger, I have to do it like this:
public class MyService
{
private ILogger _logger
public MyService()
{
_logger = LoggerFactory.BuildLogger("myType");
}
But I intend to save my classes without any instances, I need to use Constructor DI in MyService, and I need to enter all the Startup dependencies:
services.AddTransient<Contracts.ILogger, LoggerFactory.BuildLogger("param") > ();
, .
DI, ?