Use the logging generator in LoggingChatClient / LoggingEmbeddingGenerator - #5508
Conversation
| [LoggerMessage(LogLevel.Trace, "{MethodName} invoked: {ChatMessages}. Options: {ChatOptions}. Metadata: {ChatClientMetadata}.")] | ||
| private partial void LogInvokedSensitive(string methodName, string chatMessages, string chatOptions, string chatClientMetadata); |
There was a problem hiding this comment.
As it's already checked if the LogLevel is enabled, there's no need for the SGen to generate that check too. So set
| [LoggerMessage(LogLevel.Trace, "{MethodName} invoked: {ChatMessages}. Options: {ChatOptions}. Metadata: {ChatClientMetadata}.")] | |
| private partial void LogInvokedSensitive(string methodName, string chatMessages, string chatOptions, string chatClientMetadata); | |
| [LoggerMessage(LogLevel.Trace, "{MethodName} invoked: {ChatMessages}. Options: {ChatOptions}. Metadata: {ChatClientMetadata}.", SkipEnabledCheck = true)] | |
| private partial void LogInvokedSensitive(string methodName, string chatMessages, string chatOptions, string chatClientMetadata); |
in order to avoid the redundant check be emitted.
Same on other places.
There was a problem hiding this comment.
I didn't do so because these are only Debug/Trace events, and in the case where such events are enabled, the extra interface call will be dwarfed by all the JSON serialization and other overheads. And while I could just enable it anyway, not all of the call sites are currently guarded, which makes it complicated for someone maintaining the code to know which call sites need guarding and which don't. Which then leads to consistently putting SkipEnabledCheck on all of the log methods and consistently guarding all call sites, but that in turn makes the code more expensive. Seemed best to just keep it simple and pay for the extra enabled check when there's already a ton of overhead / when debugging.
Microsoft Reviewers: Open in CodeFlow