Background and motivation
When a generated logger method is called from multiple places, it can help debugging if we had the call site information. The compiler already knows how to emit those automatically using the CallerLineNumber and CallerFilePath attributes. By generating additional overloads tagged with OverloadResolutionPriority, we can easily get this information into each log call.
This can be an optional behavior enabled using an MSBuild property or an assembly/class attribute.
API Proposal
User code:
[EmitCallSiteInformation]
static partial class LoggerExtensions
{
public static partial void LogMethod(ILogger logger);
}
Generated code:
static partial class LoggerExtensions
{
public static partial void LogMethod(ILogger logger) => LogMethod(logger, default, default);
[OverloadResolutionPriority(1)]
public static void LogMethod(ILogger logger, [CallerFilePath] string? filePath = default, [CallerLineNumber] int lineNumber = default) ...
}
API Usage
See above
Alternative Designs
No response
Risks
No response
Background and motivation
When a generated logger method is called from multiple places, it can help debugging if we had the call site information. The compiler already knows how to emit those automatically using the
CallerLineNumberandCallerFilePathattributes. By generating additional overloads tagged withOverloadResolutionPriority, we can easily get this information into each log call.This can be an optional behavior enabled using an MSBuild property or an assembly/class attribute.
API Proposal
User code:
Generated code:
API Usage
See above
Alternative Designs
No response
Risks
No response