Heuristic:Microsoft Semantic kernel Telemetry Log Level Configuration
| Knowledge Sources | |
|---|---|
| Domains | Observability, Security |
| Last Updated | 2026-02-11 20:00 GMT |
Overview
Production logging configuration guidance: never enable Trace level in production as it exposes sensitive data including API keys, prompt content, and function arguments.
Description
Semantic Kernel uses the standard .NET ILogger infrastructure with five log levels. The Trace level logs sensitive data including rendered prompts, function arguments (which may contain user data or API keys), and full plan details. This creates a significant security risk if enabled in production environments. The recommended production configuration filters Microsoft logs to Warning level while keeping Semantic Kernel logs at Information level for operational visibility.
Usage
Use this heuristic when configuring logging for any Semantic Kernel deployment, particularly when moving from development to staging or production environments. Also apply when implementing OpenTelemetry exporters or integrating with monitoring platforms like Application Insights or Aspire Dashboard.
The Insight (Rule of Thumb)
- Action: Set Trace-level logging only in test/development environments. Never enable in production.
- Value: Production filter:
builder.AddFilter("Microsoft", LogLevel.Warning); builder.AddFilter("Microsoft.SemanticKernel", LogLevel.Information); - Trade-off: Information level provides plan execution status and timing without sensitive data. Trace level provides full prompt content and arguments for debugging but exposes secrets.
- Logger creation: Always create loggers via
ILoggerFactoryregistered in the service collection, not by directILoggerconstruction.
Reasoning
The Trace level in Semantic Kernel logs the following sensitive data:
- Goal/Ask strings used to create plans
- Full prompt templates and rendered versions (may contain injected user data)
- Created plans with function arguments (arguments frequently contain API keys, user credentials, or PII)
- Arguments passed to individual functions
This data is logged in plaintext. If a monitoring system ingests these logs and is accessed by unauthorized personnel, or if logs are stored in insufficiently secured storage, sensitive data is exposed. The Information level provides sufficient operational data (model used, execution status, timing) without sensitive content.
The three available meters (Microsoft.SemanticKernel.Planning, Microsoft.SemanticKernel, Microsoft.SemanticKernel.Connectors.OpenAI) provide quantitative metrics (token counts, durations) that are safe for production telemetry.
Code Evidence
Security warning from dotnet/docs/TELEMETRY.md:16:
Trace - this type of logs **should not be enabled in production environments**,
since it may contain sensitive data. It can be useful in test environments for
better observability. Logged information includes:
- Goal/Ask to create a plan
- Prompt (template and rendered version) for AI to create a plan
- Created plan with function arguments (arguments may contain sensitive data)
- Prompt (template and rendered version) for AI to execute a function
- Arguments to functions (arguments may contain sensitive data)
Recommended log filter configuration from dotnet/docs/TELEMETRY.md:65-66:
builder.AddFilter("Microsoft", LogLevel.Warning);
builder.AddFilter("Microsoft.SemanticKernel", LogLevel.Information);
Logger factory injection pattern from dotnet/docs/TELEMETRY.md:39-45:
IKernelBuilder builder = Kernel.CreateBuilder();
// Assuming loggerFactory is already defined.
builder.Services.AddSingleton(loggerFactory);
var kernel = builder.Build();