You need to install the Microsoft.Extensions.Logging.Log4Net.AspNetCore NuGet package and add a log4net.config-file to your application. Then this should work:
public class Program
{
private readonly ILogger<Program> logger;
public Program()
{
var services = new ServiceCollection()
.AddLogging(logBuilder => logBuilder.SetMinimumLevel(LogLevel.Debug))
.BuildServiceProvider();
logger = services.GetService<ILoggerFactory>()
.AddLog4Net()
.CreateLogger<Program>();
}
static void Main(string[] args)
{
Program program = new Program();
program.Run();
Console.WriteLine("\n\nPress any key to continue...");
Console.ReadKey();
}
private void Run()
{
logger.LogInformation("Logging is working");
}
}