ASP Core 2 in IIS, Console Application
in the project properties. Visual studio 2017 Community.
I'm trying to log to the console, but the console is not showing up at all.
The objective is to simply show up the console for logging purposes while having the browser connection.
I've configured the application in BuildWebHost
so that:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((builderContext, config) =>
{
IHostingEnvironment env = builderContext.HostingEnvironment;
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConsole();
logging.AddDebug();
})
.UseNLog()
.UseStartup<Startup>()
.Build();
To add further context:
- I'm able to correctly log to file with NLog
- I see the logging messages in the Output
window in VS
- I know how to send and see log messages into the browser.
I just want to fire the application in debug mode to visual studio and having the console windows opening up. Is that possible?
Running the application with dotnet-run from a command prompt is not a solution as I wouldn't have the edit and continue feature.
Normally, when you create a new ASP Core 2 Console Application
, you can see the console by simply doing Console.WriteLine("Hello world");
in the Program
method. In my app, however, this does not show up the console.
I know that the reason probably lies in the fact that the Console output is being redirected or not-existing; in fact, if I do Console.ReadKey();
I get the following:
'Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.'
Any hint is appreciated.
A couple of references/test tried to no avail: