Search code examples
asp.netvisual-studioasp.net-coreiis-express

Asp.net core + IIS Express. How to view log messages?


I'm trying to print a log message in ASP.NET Core this way:

Console.WriteLine( "Hello World!" );

loggerFactory.MinimumLevel = LogLevel.Debug;
loggerFactory.AddConsole( LogLevel.Debug );
var logger = loggerFactory.CreateLogger("Startup");
logger.LogWarning( "Hi!" );

Where can I see this message?

The Output window doesn't contain this message.

If I run the project as Web, it runs the dnx console where I can see the message, but it is not convenient.

If I run project as IIS Express I don't see the console, or the message.

Is there way to view the message in Visual Studio?


Solution

  • You can use the Debug listener to achieve what you want:

    "dependencies": {
      "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final"
    }
    

    Console.WriteLine( "Hello World!" );
    
    loggerFactory.MinimumLevel = LogLevel.Debug;
    loggerFactory.AddDebug( LogLevel.Debug );
    var logger = loggerFactory.CreateLogger("Startup");
    logger.LogWarning( "Hi!" );