我已经设置了一个使用Application Insights的应用程序,并且我试图手动记录一些自定义信息。这是我的控制器:
public class MyController : Controller
{
private ILogger<MyController> Logger { get; set; }
public MyController(ILogger<MyController> logger)
{
Logger = logger;
}
public IActionResult Index()
{
Logger.LogCritical("Test critical");
Logger.LogError("Test error");
Logger.LogWarning("Test warning");
Logger.LogInformation("Test information");
Logger.LogDebug("Test debug");
Logger.LogTrace("Test trace");
...
}
我在Startup.cs中有这个文件:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Warning);
...
}
这在我的Program.cs中:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseStartup<Startup>()
.Build();
在我的appsettings.json中:
"Logging": {
"IncludeScopes": false,
"ApplicationInsights": {
"LogLevel": {
"Default": "Warning"
}
},
"LogLevel": {
"Default": "Warning"
}
}
当我在Azure门户中查看Application Insights时,记录的唯一内容是:
因此出于某种原因跳过了一些,仅记录了严重,警告和错误。我主要想使用LogInformation
。
我的日志记录设置或启动文件中是否需要更改?