48

ASP.Net Core documentation here has a nice console logging output like in the picture below with colors for various LogLevels. I have now created an application in Visual Studio and I see that it now runs behind IIS Express and I don't see the console anymore. I remember when I did run beta, then it did pop up Kestrel directly with this nice Console output.

Is it possible to get this nice window now?

P.S. It's a bit strange that the documentation still contains these images that you cannot even see.

enter image description here

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
  • 10
    I have found that it is possible to do if you switch the profile that you are using from IISExpress to the one that has project name, then it seems Kestrel is run directly and I see output. This still leaves a question if it is possible to use with IISExpress. – Ilya Chernomordik Oct 20 '16 at 08:04
  • Ilya can you provide more info? Just selecting the non-IIS Profile does not change anything for me. – Daniel Williams Dec 22 '19 at 05:34
  • Sorry, that was enough for me: switch to direct kestrel profile. Then I got a nice console with logging, perhaps you did not set up logging correctly? – Ilya Chernomordik Dec 22 '19 at 21:23
  • @DanielWilliams before you run the project press dropdown next to green run button on visual studio and select your project name instead of iis expres.So visual studio run itself without iis express and you can see the console. – BMErEr Jan 03 '20 at 13:15

2 Answers2

28

In addition to Dawid Rutkowski's answer, on the top dropdown, don't select IISExpress, select the application name. You should be able to see the console and the web page.

Pang
  • 9,564
  • 146
  • 81
  • 122
maxspan
  • 13,326
  • 15
  • 75
  • 104
  • In VS2019 community this worked for me to get the console output (in nice Window as OP asked) without adding Nuget package or code in the startup. – Dush Feb 27 '20 at 01:59
  • I'm up-voting this because it's the most relevant answer. Select the application name instead of IISExpress, and run. No need to add anything to startup. Console.writeline will come up on the console just like that – Akin_Glen May 22 '20 at 15:10
  • 1
    For clarity, "top dropdown" is accessed by double clicking on Properties > Debug > Profile: [app name] > Launch: [Project] and then view the Output window. – Doug Dekker Oct 13 '20 at 15:34
  • Is there a way to use this answer when the solution is set to use multiple startup projects? – Bradley Uffner Feb 18 '22 at 13:05
  • 1
    I don't see this option. VS2022 Community – koral May 26 '23 at 09:27
15

Yes, it's possible with IIS Express. Use Microsoft.Extensions.Logging.Debug nuget package: https://github.com/aspnet/Logging/tree/master/src/Microsoft.Extensions.Logging.Debug. Configure logger in the Startup.cs:

loggerFactory.MinimumLevel = LogLevel.Debug;
loggerFactory.AddDebug( LogLevel.Debug );
var logger = loggerFactory.CreateLogger("Startup");
logger.LogWarning("Logger configured!");

And:

Console.WriteLine("Hi!");
Dawid Rutkowski
  • 2,658
  • 1
  • 29
  • 36
  • 1
    I already use the debug output, but that does not show up nicely in the console, but in the output window in Visual Studio without all the nice colors – Ilya Chernomordik Oct 20 '16 at 08:48
  • 2
    You are using console to get nice colors or to get useful informations? – Dawid Rutkowski Oct 20 '16 at 08:49
  • 5
    Well for once it allows to easily see an error, so that's quite useful for me. – Ilya Chernomordik Oct 20 '16 at 09:41
  • Another thing is that debug logger does not differentiate between System, Microsoft and default, so you can't have different logging levels – Ilya Chernomordik Oct 20 '16 at 10:54
  • I know the comment is old, but [this documentation](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1#configure-logging) shows that filters can be applied to categories for individual logging providers (ie debug) – Josh Gust Sep 15 '20 at 21:43
  • 4
    This answer is missing a lot of information that will make it very hard for newer asp.net coders (such as myself) to figure out exactly how it's meant to be used. – Taegost Jan 13 '21 at 17:34