Reputation: 3590
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?
Upvotes: 10
Views: 14559
Reputation: 1521
None of the other answers addresses the actual question: "How can we see those messages when running the project with IIS Express?". So, I decided to add my own, I hope it helps somebody.
The usual console window does not show up when you choose IIS Express. But you can still see those messages by following the below steps.
Output
window in Visual Studio. If you already have it, skip the next stepCtrl + W,O
. The output window will show up.I am using VS 2019, the above steps can differ based on your IDE version.
Upvotes: 10
Reputation: 42010
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!" );
Upvotes: 5
Reputation: 6398
IIS Express will not output its logs to Visual Studio's output window.
You'll need to use a different log provider.
Write it to a log file. You can use a library for that, for example Serilog:
using Serilog;
public class Startup
{
public Startup(IHostingEnvironment env)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.File("log.txt")
.CreateLogger();
...
public void Configure(IApplicationBuilder app, IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
loggerFactory.AddSerilog();
You'll need this NuGet package.
Upvotes: 4
Reputation: 2687
Go to Documents => IISExpress => Logs.
This is what you are looking for.
Upvotes: 2