我正在尝试在一个.Net Core API中实现日志记录,但是找不到日志文件。
我使用Microsoft.Extensions.Logging;和ILogger工厂方法。
在我的Program.cs中...
var host = new WebHostBuilder()
.UseApplicationInsights()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
在我的 Startup.cs 中,在 Configure 方法中有以下内容...
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Warning);
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
loggerFactory.AddEventSourceLogger();
在我的 appsettings.json 中,有这样一段代码...
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
在我的控制器中,我注入了日志记录器并以以下方式调用了该方法...
_logger.LogError("ERROR_MESSAGE_STRING");
LogError方法正在使用错误字符串调用,但我没有看到日志。 我希望在某个地方看到日志错误文件。也许在bin目录中?
.Add*
调用。 - Daniel A. White