Entering Program.cs

Is it possible to get ILogger inside the main method of Program.cs? I want to pass it to a service created inside this method.

I found this only on SO. How to write logs from Startup.cs , but this is registration in Startup.cs.

+4
source share
1 answer

I stumbled upon an answer after I entered the game a little more.

using System;
using Microsoft.Extensions.Logging;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var logFactory = new LoggerFactory()
            .AddConsole(LogLevel.Debug)
            .AddDebug();

            var logger = logFactory.CreateLogger<Type>();

            logger.LogInformation("this is debug log");
        }
    }
}

Kudos https://askguanyu.wordpress.com/2016/09/26/net-core-101-e06-net-core-logging/

+2
source

Source: https://habr.com/ru/post/1681896/


All Articles