I am following this article: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1
I am trying to only log my own custom logging in a asp.net core 3.1 API. And not all logs generated from asp.net core. I have created a blank weather forecast service:
[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": "*"
}
I have following nuget installed both version 2.14.0: Microsoft.Extensions.Logging.ApplicationInsights Microsoft.ApplicationInsights.AspNetCore
Now I try to run the app, but gets no logs.
I try adding services.AddApplicationInsightsTelemetry(); to startup:
public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry();
services.AddControllers();
}
Same no logs.