4

I generated a new project for ASP.Net Core 2.0. Added this code in Program.cs:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); ... 

Then I go to the folder containing the project and run dotnet run:

Hosting environment: Development Content root path: C:\Users\arthur\Source\Repos\WebApplication5\WebApplication5 Now listening on: http://localhost:3000 Application started. Press Ctrl+C to shut down 

While navigating the site I want to see the logs generated by framework but I see nothing. Though if I generate ASP.Net Core 1.1 web project the lines with logging are already in Program.cs and I see the logs:

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1] Request starting HTTP/1.1 GET http://localhost:53680/ info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1] Executing action method WebApplication3.Controllers.HomeController.Index (WebApplication3) with arguments ((null)) - ModelState is Valid 

What am I missing?

3
  • as per MSDN you need to add .AddDebug(); to program.cs if you want core to log the changes, but you need to use log LogWarning``LogInformation to log things you want. learn.microsoft.com/en-us/aspnet/core/fundamentals/logging Commented Jul 13, 2017 at 15:57
  • AddDebug() just adds logging to debug console of visual studio, with Log[Level] you just log what you want to log and I am interested in logs produced by ASP.Net itself, like ` Executing action method WebApplication3.Controllers.HomeController.Index (WebApplication3) with arguments ((null)) - ModelState is Valid` Commented Jul 13, 2017 at 16:25
  • Did you check learn.microsoft.com/en-us/aspnet/core/fundamentals/… Commented Jul 13, 2017 at 16:41

1 Answer 1

7

Ok, I feel a bit stupid now, but to achieve what I wanted I had to change LogLevel of Debug and Console in appsettings.json to something lower that Warning

Sign up to request clarification or add additional context in comments.

1 Comment

You could also add a file appsettings.Development.json to overwrite the LogLevel only for the Development environment. The method CreateDefaultBuilder in Program.cs automatically adds the configurations for the current environment.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.