I had configured my ASP.NET Core application to use Application Insights for logging. However when I took a look at the logged messages inside Application Insights, nothing was logged? What did I do wrong?
The only code I added to enable logging was this:
But I couldn’t see what could be wrong in this one line…
I searched through the documentation to find a solution. There I noticed the following sentence:
By default, ASP.NET Core applications have an Application Insights logging provider registered when they're configured through the code or codeless approach. The registered provider is configured to automatically capture log events with a severity of LogLevel.Warning or greater.
Aha! By default the ApplicationInsightsLoggerProvider
will only log messages with LogLevel Warning or higher.
Let’s change this to also log Informational messages.
There are 2 ways to do this;
- Through configuration
- Through code
Change LogLevel through configuration
To change the log level through configuration, we need to update our appsettings.json
and add an ApplicationInsights section inside our Logging configuration section:
Change LogLevel through code
A second option is to change the log level through code. This can be done through the AddFilter<>
method: