我为ASP.Net Core 2.0创建了一个新项目。在Program.cs
中添加了以下代码:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
...
然后我进入包含项目的文件夹并运行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
在浏览网站时,我希望能够看到框架生成的日志,但是我什么都没有看到。尽管如果我生成 ASP.Net Core 1.1 网络项目,则具有记录日志的行已经在 Program.cs
中,我可以看到这些日志:
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
我错过了什么?
.AddDebug();
。但是,如果您想要记录其他内容,则需要使用LogWarning
和LogInformation
。请参考以下链接:https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging - Just codeAddDebug()
just adds logging to debug console of visual studio, withLog[Level]
you just log what you want to log and I am interested in logs produced by ASP.Net itself, likeExecuting action method WebApplication3.Controllers.HomeController.Index (WebApplication3) with arguments ((null)) - ModelState is Valid
- hasrthur