Support [CallerMemberName] and similar parameters in a [LoggerMessage] #112180
Labels
area-Extensions-Logging
needs-author-action
An issue or pull request that requires more info or actions from the author.
source-generator
Indicates an issue with a source generator feature
Milestone
Description
As a developer, I use Source-generated logging to permit high-performance logging.
The specific logging provider I use supports structured logging, and it is useful to me to know where in my program a particular logging message was emitted.
In order to accomplish that, I can use the
[CallerMemberName]
,[CallerFilePath]
and[CallerLineNumber]
attributes to automatically emit the caller information into my log messages, like so:Output (when using AddJsonConsole for logging)
Problem
Unfortunately, currently this will cause 3 SYSLIB1015 warnings to be emitted:
I would like a mechanism to suppress/prevent these warnings. The suppression should be targeted so that only these warnings are supressed/prevented, as SYSLIB1015 is, in general, an extremely useful warning.
Suggested implementation
One approach would be to add an additional attribute to each parameter to indicate to the logging generator that these parameters are intended to be consumed by the logging provider, and so are intentional.
For example, there might be a
[ContextInformationAttribute]
that is used to suppress this warning, like so:This has the advantage that it is a flexible mechanism that could work for any information that is intended to be used only for structured logging (although scopes can, in general, achieve the same aim).
The text was updated successfully, but these errors were encountered: