0
votes

i am using asp.net core mvc and web api project

which has below version

 <TargetFramework>netcoreapp2.2</TargetFramework>

i'm also using Microsoft.Extensions.Logging.ILogger to log some of information

for Example : _logger.LogInformation("special information log for xyz method"); for application insight.

so as per this post https://weblog.west-wind.com/posts/2018/Dec/31/Dont-let-ASPNET-Core-Default-Console-Logging-Slow-your-App-down

i made log level like this in my local app setting project and hit play icon from visual studio and watching console logs in black window.

"LogLevel": {
      "Default": "Information",
      "System": "Warning",
      "Microsoft": "Warning"
    }

now when i do run of my application, still i'm able to see logs like this

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 35782.1232ms 200 text/html; charset=UTF-8
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://localhost:57526/polyfills.js
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://localhost:57526/styles.js
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://localhost:57526/vendor.js

Question #1 : why still i'm able to to see this log in console window where "info is from Microsoft" :(

Question #2 : what is your best recommendation(experiences) log level for production and development? i do not want to slow down my application due to wanted to log information logged to application insights.

program.cs

                    // Optional: Apply filters to control what logs are sent to Application Insights.
                    // The following configures LogLevel Information or above to be sent to
                    // Application Insights for all categories.
                    logging.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>
                                 ("", LogLevel.Information);

                }
            }
        );
1

1 Answers

1
votes

Question #1 : why still i'm able to to see this log in console window where "info is from Microsoft" :

Since you see the logging in development,you need to change log levels in appsettings.Development.json instead of appsettings.json, you could find the file just behind the appsettings.json.

enter image description here

Question #2 : what is your best recommendation(experiences) log level for production and development? i do not want to slow down my application due to wanted to log information logged to application insights.

It is documented well, refer to https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.0#log-level

In production: Logging at the Trace through Information levels produces a high-volume of detailed log messages. To control costs and not exceed data storage limits, log Trace through Information level messages to a high-volume, low-cost data store. Logging at Warning through Critical levels typically produces fewer, smaller log messages. Therefore, costs and storage limits usually aren't a concern, which results in greater flexibility of data store choice.

During development: Log Warning through Critical messages to the console. Add Trace through Information messages when troubleshooting.