You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inject an ILogger<ClassA> _logger into ClassA and call _logger.IsEnabled(LogLevel.Debug)
publicclassArgument{publicstringProperty1{get;init;}publicintProperty2{get;init;}}publicclassClassA{privatereadonlyILogger<ClassA>_logger;publicClassA(ILogger<ClassA>logger){_logger=logger;}publicvoidDoWork(Argumentarg){if(_logger.IsEnabled(LogLevel.Debug)){
_logger.LogDebug("Begining DoWork with argument: {Argument}", JsonSerializer.Serialize(arg));}else{
_logger.LogInformation("Beginning DoWork");}// ... do the work}}
Expected behavior
The Information log message should show up in Application Insights.
Actual behavior
The Debug log message shows up in Application Insights
Known workarounds
Not that I know off.
Related information
Upon inspecting the source code of ApplicationInsightsLogger, I noticed that the method IsEnabled(LogLevel) always return true. It has a comment explaining why but I think it is ignoring the fact that many code depends on this method working correctly to improve logging performance, avoiding costly code path to be executed when turned off, like in the example above where in staging environment I'd set AzureFunctionsJobHost__logging__logLevel__default to Debug to get the serialized argument object. Even MS docs recommend that way (link).
If ILogger.IsEnabled is not reliable, are there alternative ways to achieve the above?
Package version
Links to source
The text was updated successfully, but these errors were encountered:
Please provide a succinct description of the issue.
Repro steps
Provide the steps required to reproduce the problem
default
log level in host.json toInformation
ILogger<ClassA> _logger
intoClassA
and call_logger.IsEnabled(LogLevel.Debug)
Expected behavior
The Information log message should show up in Application Insights.
Actual behavior
The Debug log message shows up in Application Insights
Known workarounds
Not that I know off.
Related information
Upon inspecting the source code of
ApplicationInsightsLogger
, I noticed that the methodIsEnabled(LogLevel)
always return true. It has a comment explaining why but I think it is ignoring the fact that many code depends on this method working correctly to improve logging performance, avoiding costly code path to be executed when turned off, like in the example above where in staging environment I'd setAzureFunctionsJobHost__logging__logLevel__default
toDebug
to get the serialized argument object. Even MS docs recommend that way (link).If
ILogger.IsEnabled
is not reliable, are there alternative ways to achieve the above?The text was updated successfully, but these errors were encountered: