Azure-docs: Adding Filters to a .Net Core Console application

Created on 9 Dec 2019  Â·  11Comments  Â·  Source: MicrosoftDocs/azure-docs

Hi,

I'm following the example here: https://docs.microsoft.com/en-us/azure/azure-monitor/app/worker-service#net-corenet-framework-console-application

I have everything set up and working, and I can see test messages from my console app appear in Application Insights but ONLY if I use LogError (which appear as severity = 3).

I want to change this so that I can see LogInformation messages in Application Insights. I have followed the link in this article to the log filtering article (here: https://docs.microsoft.com/en-us/azure/azure-monitor/app/ilogger#control-logging-level) but this talks about configuring this in appsettings.json (which comments in the Console code say is not possible) or by making calls to WebHost.CreateDefaultBuilder.ConfigureLogging….. which is also not being used in the example for the Console application :-?

The documentation is confusing.

Could it be made a little clearer?

Thanks!

PS - the example code in GitHub also does not have an example of this. I checked.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Azure-Monitosvc Pri2 application-insightsubsvc assigned-to-author doc-enhancement triaged

Most helpful comment

services.AddLogging(loggingBuilder => loggingBuilder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("Category", LogLevel.Information));

The above line can be added right after services.AddApplicationInsightsTelemetryWorkerService(). @mrbullwinkle Can you add this to doc as well?

All 11 comments

@jn-altiusThank you for the feedback! We are investigating this and will get back to you shortly.

@jn-altius We are passing this feedback to the author, and assigning this to them so that they can update the documentation accordingly. This area of Application Insights has been confusing for some of our readers and we are trying to make it easier to follow. When creating my own Console Applications, I started with our documentation here:

https://docs.microsoft.com/en-us/azure/azure-monitor/app/console

adding @cijothomas - what is the preferred method of creating logging level filter rules in a console app with the worker service SDK?

services.AddLogging(loggingBuilder => loggingBuilder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("Category", LogLevel.Information));

The above line can be added right after services.AddApplicationInsightsTelemetryWorkerService(). @mrbullwinkle Can you add this to doc as well?

@jn-altius Please give us specifics rather than just saying "documentation is confusing and make it clearer" - its not actionable.

If you meant the lack of Console App example for controlling logging level - the above comment has suggestion. Let us know if there are additional feedback.

The official Ilogger doc itself lacks anything console app specific,- all examples are asp.net core ones- https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging Hopefully this situation improves and we can adapt application insights docs as well better then.

@kobulloc-MSFT As mentioned in the doc (/app/console,), itself, the recommendation is to use this doc: https://docs.microsoft.com/en-us/azure/azure-monitor/app/worker-service
The console app doc is a good start, but it does not show setting up application insights for full monitoring capabilities. The console app doc will be deprecated/merged in favor of worker service doc in the future.

Hi @cijothomas In my original post I detailed what was confusing. The documentation I started from talked about Console applications, then when it talks about filters the link quoted is to a different tech (asp.net core), that talks about WebHost - which is nothing to do with a Console app.

But thank you, your answer above with the loggingBuilder lambda does bridge the gap between the two.

@jn-altius Thanks for confirming. We can address this confusion right away with this snippet. @mrbullwinkle Can you update the doc to include this info?

I will get this added today. Thanks @jn-altius for the question, and @cijothomas for the answer!

Updates to the doc have been merged internally. They will go-live tomorrow morning.

please-close

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spottedmahn picture spottedmahn  Â·  3Comments

AronT-TLV picture AronT-TLV  Â·  3Comments

JamesDLD picture JamesDLD  Â·  3Comments

jebeld17 picture jebeld17  Â·  3Comments

paulmarshall picture paulmarshall  Â·  3Comments