【发布时间】:2020-05-18 10:33:45
【问题描述】:
我正在关注这篇文章: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1
我正在尝试仅在 asp.net core 3.1 API 中记录我自己的自定义日志记录。并非所有从 asp.net 核心生成的日志。我创建了一个空白天气预报服务:
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
_logger.LogTrace("LogTrace");
_logger.LogDebug("LogDebug");
_logger.LogInformation("LogInformation");
_logger.LogError("LogError");
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
appsettings.json:
{
"Logging": {
"LogLevel": {
"Default": "Trace",
"Microsoft": "Trace",
"TestAPI": "Trace"
},
"ApplicationInsights": {
"InstrumentationKey": "xx-xx-x-x-xx",
"LogLevel": {
"Default": "Trace",
"Microsoft": "Trace",
"TestAPI": "Trace"
}
}
},
"AllowedHosts": "*"
}
我在 2.14.0 版本中都安装了以下 nuget: Microsoft.Extensions.Logging.ApplicationInsights Microsoft.ApplicationInsights.AspNetCore
现在我尝试运行应用程序,但没有日志。
我尝试添加 services.AddApplicationInsightsTelemetry();启动:
public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry();
services.AddControllers();
}
同样没有日志。
【问题讨论】:
标签: asp.net-core asp.net-core-webapi microsoft-extensions-logging