We have common BL classes in a ASP.NET Core application that get in the ctor:
Microsoft.Extensions.Logging.ILogger
In ASP.NET Core, the i
In Console app Main method
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
IConfigurationRoot configuration = builder.Build();
var serviceProvider = new ServiceCollection()
.AddDbContext(optionns => optionns.UseSqlServer(configuration.GetConnectionString("connectionString")))
.AddSingleton(typeof(ILogger<>), typeof(Logger<>))
.AddLogging()
.BuildServiceProvider();
MyDbContext _context = serviceProvider.GetService();
var _logger = serviceProvider.GetService>();