Include Category name in Log event when no Logging framework used (Microsoft.Extensions.Logging) #2903
Labels
community
To tag external issues and PRs
feature request
To tag an issue after triage that is a feature instead of TD
Log events captured by .Net APM agent, when no Logging framework used (plain
Microsoft.Extensions.Logging
), does not include the logging Category name.Feature Description
Log events captured when using plain
Microsoft.Extensions.Logging
, includes the following properties, taken from Console example Console exampleThe most important log properties are
level
andmessage
, captured by the .Net APM agent, but in some scenarios the log category, used tipically for filtering logs, is also useful as should contain the class name and allows locating the log source.Logging frameworks tipically include the categoy name in the information dumped. For example, Microsoft Logging in the Console log formatting Simple includes the category name, in the exapmles provided shown as
Program[0]
, Console log formattingIn the Console example linked, in the console output the log is as
info: ConsoleSample.Worker[0] Chilling for a few seconds...
whereas theConsoleSample.Worker
is the category name.Describe Alternatives
You can always manually include in the log message the class name as the log source (
ConsoleSample.Worker:
part):_logger.LogInformation("Console.Worker: Getting the weather forecast for Portland, OR");
The manual introduction of the class name as the category in every log message could be alleviated using the
BeginScope()
facility ofMicrosoft.Extensions.Logging
, a real example of this usage pattern:Additional context
Log category names are defined when you create the logger. In the Console example linked. the logger received by the
Worker
class is defined asILogger<Worker> logger
, being<Worker>
the simplest and most usual way to define the category name, using the class name.Subsequent calls to the
ILogger<Worker>
logger should include in New Relic acategory:Console.Worker
property in the log event captured and sent to the NR1 platform.As contextual logging is the common way to use the
Microsoft.Extensions.Logging
logging facilities, the category name is always defined and should not be part of the log message, thus NR should capture and include it in the log event as the log source.Priority
Nice to have
The text was updated successfully, but these errors were encountered: