Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

c# - Application Insights' Logs Not Writing to Traces Log

I am adding Application Insights (AI) to my web API service by following this page Application Insights Instructions. I managed to get my service to connect to AI and I am able to see when my service preforms a post, get, etc. I also placed log calls through my service, but none of them are being written to my AI's Traces log.

Traces Log

I made sure to setup my Startup.cs and appsettings.json files to contain the new code needed to run AI in throughout my service, and the logging data need to have AI grab logs debug and up.

Startup.cs

public void ConfigureServices(IServiceCollection services)
{         
    services.AddApplicationInsightsTelemetry();
}

appsettings.json

appsettings.json

Logging Example

public async Task ProcessQueueAsync(dBData dbContext)
{
    // _logger is of type ILogger<[INSERT CLASS NAME]>
    _logger.LogDebug("This is a test log by Lotzi11.");
    await ProcessQueueAsyncSingle(dbContext, CancellationToken.None);
}

Can someone help me figure out why my logs are not being sent to AI?

question from:https://stackoverflow.com/questions/66052823/application-insights-logs-not-writing-to-traces-log

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your code configuration and appsettings.json are correct. I can see these logs in AI as per your settings at my side.

One thing you should know is that, it may take a few minutes for these data to arrive in AI server. Please wait for a few minutes, like 5 minutes or more, then query these data again from azure portal -> application insights.

And here is a simple way to check if the data is sent to AI. In visual studio, when running the project, you can search the logs in visual studio output window. If you can find the logs there, then it should be sent to AI:

Search in visual studio output window:

enter image description here

If you still cannot see the these logs in AI, you should also check if you have set something like filter or sampling in your code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...