asp.net-core.net-coreloggerfactory

.NET Core API LoggerFactory


I have a .NET Core API project (Core 2.2) like this

namespace TestApplication2
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();

            ILoggerFactory loggerFactory = new LoggerFactory()
                .AddConsole()
                .AddDebug();
            ILogger logger = loggerFactory.CreateLogger<Program>();
            logger.LogInformation(
            "This is a test of the emergency broadcast system.");
       }

       public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
       }
    }
}

Can anyone inform me where can I find the logging output? In VS output tab I can see nothing.

In here

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-2.1

it mentions something about console but I run the app from VS2017


Solution

  • In this configuration (AddConsole, AddDebug) if you run the application in console mode (instead of IIS Express), you can see the outputs in the Console.

    To do that, click on the small arrow next to the run button, select your project name.