Logging in .Net core console application not working

前端 未结 3 1856
孤街浪徒
孤街浪徒 2021-01-02 19:07

I am following this tutorial: https://andrewlock.net/using-dependency-injection-in-a-net-core-console-application/

and accordingly installed the packages but log is

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 19:44

    Turns out the console logging provider doesn't immediately flush the messages to the console like it did in the net-core-1.x versions. It appears to run on a different thread. See this web page for info: https://github.com/aspnet/Logging/issues/631

    You can add at the end of the Main function.

    serviceProvider.Dispose();
    

    or you can add .AddDebug()

                serviceProvider
                .GetService()
                .AddConsole(LogLevel.Debug)
                .AddDebug();
    

提交回复
热议问题