var services = new ServiceCollection();
//add logging
services.AddLogging();
//build the provider;
var serviceProvider = services.BuildServiceProvider();
Source: AndrewLock.Net
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
loggerFactory.AddNLog();
loggerFactory.ConfigureNLog("nlog.config");
logger = serviceProvider.GetService<ILoggerFactory>()
.CreateLogger<Program>();
logger.LogInformation("Hello World!");