Ste*_*ven 4 c# asp.net azure azure-application-insights
我有一个应用程序设置为使用 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");
...
}
Run Code Online (Sandbox Code Playgroud)
我的 Startup.cs 中有这个:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Warning);
...
Run Code Online (Sandbox Code Playgroud)
}
这在我的 Program.cs 中:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseStartup<Startup>()
.Build();
Run Code Online (Sandbox Code Playgroud)
在我的 appsettings.json 中:
"Logging": {
"IncludeScopes": false,
"ApplicationInsights": {
"LogLevel": {
"Default": "Warning"
}
},
"LogLevel": {
"Default": "Warning"
}
}
Run Code Online (Sandbox Code Playgroud)
当我在 Azure 门户中查看 Application Insights 时,唯一记录的内容是:
因此,由于某种原因,它会跳过一些内容,只记录“严重”、“警告”和“错误”。我主要想用LogInformation.
我需要在日志设置或启动文件中更改某些内容吗?
如果要收集所有遥测数据,则不应Warning在appsettings.json. 日志Warning级别只会收集Warning//Error数据Critical,而放弃Trace//Debug数据Information。
请指定应用程序见解的日志级别,如下Trace所示appsettings.json:
"Logging": {
"IncludeScopes": false,
"ApplicationInsights": {
"LogLevel": {
"Default": "Trace"
}
},
"LogLevel": {
"Default": "Warning"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6578 次 |
| 最近记录: |