How to use ILoggerFactory and log to the console

3.2k views Asked by At

I created a simple console application in .Net Core 3.1. I want to create a logger and print it to the console.

I have the following code

class Program
{
    public static void Main(string[] args)
    {
        var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
        var logger = loggerFactory.CreateLogger(nameof(Program));
        logger.LogInformation("some logging info");
    }
}

when I run the command dotnet run nothing is printed.

Is there something else I need to configure?

0

There are 0 answers