ln-771-logging-configurator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseln-771-logging-configurator
ln-771-logging-configurator
Type: L3 Worker
Category: 7XX Project Bootstrap
Parent: ln-770-crosscutting-setup
Configures structured JSON logging for .NET and Python projects.
类型: L3 Worker
分类: 7XX 项目初始化
父项: ln-770-crosscutting-setup
为.NET和Python项目配置结构化JSON日志。
Overview
概述
| Aspect | Details |
|---|---|
| Input | Context Store from ln-770 |
| Output | Logging configuration files |
| Stacks | .NET (Serilog), Python (structlog) |
| 方面 | 详情 |
|---|---|
| 输入 | 来自ln-770的上下文存储 |
| 输出 | 日志配置文件 |
| 技术栈 | .NET(Serilog)、Python(structlog) |
Phase 1: Receive Context
阶段1:接收上下文
Accept Context Store from coordinator.
Required Context:
- : .NET or Python
STACK - : ASP.NET Core or FastAPI
FRAMEWORK - : Version number
FRAMEWORK_VERSION - : Project directory path
PROJECT_ROOT - : Development or Production
ENVIRONMENT
Validation:
- If not provided, detect from project files
STACK - If version not provided, use latest stable
接收来自协调器的上下文存储。
必需上下文:
- :.NET 或 Python
STACK - :ASP.NET Core 或 FastAPI
FRAMEWORK - :版本号
FRAMEWORK_VERSION - :项目目录路径
PROJECT_ROOT - :开发或生产
ENVIRONMENT
验证:
- 如果未提供,从项目文件中检测
STACK - 如果未提供版本,使用最新稳定版
Phase 2: Research Current Best Practices
阶段2:调研当前最佳实践
Use MCP tools to get up-to-date documentation.
For .NET (Serilog):
MCP ref: "Serilog ASP.NET Core structured logging configuration"
Context7: /serilog/serilog-aspnetcoreFor Python (structlog):
MCP ref: "structlog Python structured logging configuration"
Context7: /hynek/structlogKey Patterns to Research:
- Request logging middleware
- Log enrichment (correlation ID, user context)
- Log level configuration by environment
- Sink configuration (Console, File, Seq, Elastic)
使用MCP工具获取最新文档。
针对.NET(Serilog):
MCP ref: "Serilog ASP.NET Core structured logging configuration"
Context7: /serilog/serilog-aspnetcore针对Python(structlog):
MCP ref: "structlog Python structured logging configuration"
Context7: /hynek/structlog需调研的核心模式:
- 请求日志中间件
- 日志增强(关联ID、用户上下文)
- 按环境配置日志级别
- Sink配置(控制台、文件、Seq、Elastic)
Phase 3: Decision Points
阶段3:决策点
Ask user for configuration preferences.
询问用户配置偏好。
Q1: Log Format
Q1:日志格式
| Option | When to Use |
|---|---|
| JSON (Recommended for Production) | Machine-readable, log aggregation systems |
| Pretty/Colored (Recommended for Development) | Human-readable, local debugging |
| 选项 | 使用场景 |
|---|---|
| JSON(生产环境推荐) | 机器可读,适用于日志聚合系统 |
| 美化/彩色(开发环境推荐) | 人类可读,适用于本地调试 |
Q2: Enrichment Fields
Q2:增强字段
| Field | Description | Default |
|---|---|---|
| Request tracking across services | ✓ Yes |
| Authenticated user identifier | ✓ Yes |
| HTTP request path | ✓ Yes |
| Request duration in ms | ✓ Yes |
| Server hostname | Optional |
| Thread identifier | Optional |
| 字段 | 描述 | 默认值 |
|---|---|---|
| 跨服务的请求追踪 | ✓ 是 |
| 已认证用户标识符 | ✓ 是 |
| HTTP请求路径 | ✓ 是 |
| 请求耗时(毫秒) | ✓ 是 |
| 服务器主机名 | 可选 |
| 线程标识符 | 可选 |
Q3: Log Sinks
Q3:日志Sink
| Sink | Use Case |
|---|---|
| Console | Always enabled |
| File | Local persistence, log rotation |
| Seq | Structured log server |
| Elasticsearch | Log aggregation at scale |
| Sink | 使用场景 |
|---|---|
| 控制台 | 始终启用 |
| 文件 | 本地持久化,日志轮转 |
| Seq | 结构化日志服务器 |
| Elasticsearch | 大规模日志聚合 |
Q4: Log Levels by Environment
Q4:按环境配置日志级别
| Level | Development | Production |
|---|---|---|
| Default | Debug | Information |
| Microsoft.* | Information | Warning |
| System.* | Information | Warning |
| Application | Debug | Information |
| 级别 | 开发环境 | 生产环境 |
|---|---|---|
| 默认 | Debug | Information |
| Microsoft.* | Information | Warning |
| System.* | Information | Warning |
| 应用程序 | Debug | Information |
Phase 4: Generate Configuration
阶段4:生成配置
Generate files based on stack and decisions.
根据技术栈和决策生成文件。
.NET Output Files
.NET输出文件
| File | Purpose |
|---|---|
| Service registration |
| Serilog configuration |
| Dev overrides |
Generation Process:
- Use MCP ref to get current Serilog API
- Generate LoggingExtensions.cs with:
- UseSerilog configuration
- Request logging middleware
- Enrichment configuration
- Update appsettings.json with Serilog section
Packages to Add:
Serilog.AspNetCoreSerilog.Sinks.Console- (if File sink selected)
Serilog.Sinks.File - (if machineName selected)
Serilog.Enrichers.Environment
| 文件 | 用途 |
|---|---|
| 服务注册 |
| Serilog配置 |
| 开发环境覆盖配置 |
生成流程:
- 使用MCP参考获取当前Serilog API
- 生成LoggingExtensions.cs,包含:
- UseSerilog配置
- 请求日志中间件
- 增强配置
- 更新appsettings.json中的Serilog配置段
需添加的包:
Serilog.AspNetCoreSerilog.Sinks.Console- (如果选择文件Sink)
Serilog.Sinks.File - (如果选择machineName)
Serilog.Enrichers.Environment
Python Output Files
Python输出文件
| File | Purpose |
|---|---|
| structlog configuration |
| Request logging |
Generation Process:
- Use MCP ref to get current structlog API
- Generate logging_config.py with:
- Processor chain configuration
- Renderer selection (JSON/Console)
- Log level configuration
- Generate logging_middleware.py for FastAPI
Packages to Add:
structlog- (if JSON format)
python-json-logger
| 文件 | 用途 |
|---|---|
| structlog配置 |
| 请求日志 |
生成流程:
- 使用MCP参考获取当前structlog API
- 生成logging_config.py,包含:
- 处理器链配置
- 渲染器选择(JSON/控制台)
- 日志级别配置
- 为FastAPI生成logging_middleware.py
需添加的包:
structlog- (如果选择JSON格式)
python-json-logger
Phase 5: Validate
阶段5:验证
Verify the configuration works.
Validation Steps:
-
Check imports: Ensure all packages are available
- .NET:
dotnet list package | grep Serilog - Python:
pip list | grep structlog
- .NET:
-
Syntax check:
- .NET:
dotnet build --no-restore - Python:
python -m py_compile core/logging_config.py
- .NET:
-
Test log output:
- Start application
- Make test request
- Verify log format matches configuration
Expected Log Format:
json
{
"timestamp": "2026-01-10T12:00:00.000Z",
"level": "info",
"message": "Request completed",
"correlationId": "abc-123",
"requestPath": "/api/health",
"responseTime": 45,
"statusCode": 200
}验证配置是否可用。
验证步骤:
-
检查依赖包: 确保所有包已安装
- .NET:
dotnet list package | grep Serilog - Python:
pip list | grep structlog
- .NET:
-
语法检查:
- .NET:
dotnet build --no-restore - Python:
python -m py_compile core/logging_config.py
- .NET:
-
测试日志输出:
- 启动应用程序
- 发起测试请求
- 验证日志格式与配置一致
预期日志格式:
json
{
"timestamp": "2026-01-10T12:00:00.000Z",
"level": "info",
"message": "Request completed",
"correlationId": "abc-123",
"requestPath": "/api/health",
"responseTime": 45,
"statusCode": 200
}Return to Coordinator
返回至协调器
Return result to ln-770:
json
{
"status": "success",
"files_created": [
"Extensions/LoggingExtensions.cs",
"appsettings.json"
],
"packages_added": [
"Serilog.AspNetCore",
"Serilog.Sinks.Console"
],
"registration_code": "services.AddLoggingServices(configuration);",
"message": "Configured structured logging with Serilog"
}向ln-770返回结果:
json
{
"status": "success",
"files_created": [
"Extensions/LoggingExtensions.cs",
"appsettings.json"
],
"packages_added": [
"Serilog.AspNetCore",
"Serilog.Sinks.Console"
],
"registration_code": "services.AddLoggingServices(configuration);",
"message": "Configured structured logging with Serilog"
}Idempotency
幂等性
This skill is idempotent:
- Phase 1: Check if logging already configured (Grep for Serilog/structlog)
- If configured: Return
{ "status": "skipped", "message": "Logging already configured" } - If not: Proceed with configuration
此工具具备幂等性:
- 阶段1:检查日志是否已配置(搜索Serilog/structlog)
- 如果已配置:返回
{ "status": "skipped", "message": "Logging already configured" } - 如果未配置:继续执行配置流程
Reference Links
参考链接
Version: 2.0.0
Last Updated: 2026-01-10