LoggingAgentBuilderExtensions.UseLogging Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds logging to the agent pipeline, enabling detailed observability of agent operations.
public static Microsoft.Agents.AI.AIAgentBuilder UseLogging(this Microsoft.Agents.AI.AIAgentBuilder builder, Microsoft.Extensions.Logging.ILoggerFactory? loggerFactory = default, Action<Microsoft.Agents.AI.LoggingAgent>? configure = default);
static member UseLogging : Microsoft.Agents.AI.AIAgentBuilder * Microsoft.Extensions.Logging.ILoggerFactory * Action<Microsoft.Agents.AI.LoggingAgent> -> Microsoft.Agents.AI.AIAgentBuilder
<Extension()>
Public Function UseLogging (builder As AIAgentBuilder, Optional loggerFactory As ILoggerFactory = Nothing, Optional configure As Action(Of LoggingAgent) = Nothing) As AIAgentBuilder
Parameters
- builder
- AIAgentBuilder
The AIAgentBuilder to which logging support will be added.
- loggerFactory
- ILoggerFactory
An optional ILoggerFactory used to create a logger with which logging should be performed. If not supplied, a required instance will be resolved from the service provider.
- configure
- Action<LoggingAgent>
An optional callback that provides additional configuration of the LoggingAgent instance. This allows for fine-tuning logging behavior such as customizing JSON serialization options.
Returns
The AIAgentBuilder with logging support added, enabling method chaining.
Exceptions
builder is null.
Remarks
When the employed ILogger enables Trace, the contents of messages, options, and responses are logged. These may contain sensitive application data. Trace is disabled by default and should never be enabled in a production environment. Messages and options are not logged at other logging levels.
If the resolved or provided ILoggerFactory is NullLoggerFactory, this will be a no-op where logging will be effectively disabled. In this case, the LoggingAgent will not be added.