Get the FREE Ultimate OpenClaw Setup Guide →

ln-771-logging-configurator

npx machina-cli add skill levnikolaevich/claude-code-skills/ln-771-logging-configurator --openclaw
Files (1)
SKILL.md
6.4 KB

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.


Overview

AspectDetails
InputContext Store from ln-770
OutputLogging configuration files
Stacks.NET (Serilog), Python (structlog)

Phase 1: Receive Context

Accept Context Store from coordinator.

Required Context:

  • STACK: .NET or Python
  • FRAMEWORK: ASP.NET Core or FastAPI
  • FRAMEWORK_VERSION: Version number
  • PROJECT_ROOT: Project directory path
  • ENVIRONMENT: Development or Production

Validation:

  • If STACK not provided, detect from project files
  • If version not provided, use latest stable

Phase 2: Research Current Best Practices

Use MCP tools to get up-to-date documentation.

For .NET (Serilog):

MCP ref: "Serilog ASP.NET Core structured logging configuration"
Context7: /serilog/serilog-aspnetcore

For Python (structlog):

MCP ref: "structlog Python structured logging configuration"
Context7: /hynek/structlog

Key Patterns to Research:

  1. Request logging middleware
  2. Log enrichment (correlation ID, user context)
  3. Log level configuration by environment
  4. Sink configuration (Console, File, Seq, Elastic)

Phase 3: Decision Points

Ask user for configuration preferences.

Q1: Log Format

OptionWhen to Use
JSON (Recommended for Production)Machine-readable, log aggregation systems
Pretty/Colored (Recommended for Development)Human-readable, local debugging

Q2: Enrichment Fields

FieldDescriptionDefault
correlationIdRequest tracking across services✓ Yes
userIdAuthenticated user identifier✓ Yes
requestPathHTTP request path✓ Yes
responseTimeRequest duration in ms✓ Yes
machineNameServer hostnameOptional
threadIdThread identifierOptional

Q3: Log Sinks

SinkUse Case
ConsoleAlways enabled
FileLocal persistence, log rotation
SeqStructured log server
ElasticsearchLog aggregation at scale

Q4: Log Levels by Environment

LevelDevelopmentProduction
DefaultDebugInformation
Microsoft.*InformationWarning
System.*InformationWarning
ApplicationDebugInformation

Phase 4: Generate Configuration

Generate files based on stack and decisions.

.NET Output Files

FilePurpose
Extensions/LoggingExtensions.csService registration
appsettings.json (update)Serilog configuration
appsettings.Development.json (update)Dev overrides

Generation Process:

  1. Use MCP ref to get current Serilog API
  2. Generate LoggingExtensions.cs with:
    • UseSerilog configuration
    • Request logging middleware
    • Enrichment configuration
  3. Update appsettings.json with Serilog section

Packages to Add:

  • Serilog.AspNetCore
  • Serilog.Sinks.Console
  • Serilog.Sinks.File (if File sink selected)
  • Serilog.Enrichers.Environment (if machineName selected)

Python Output Files

FilePurpose
core/logging_config.pystructlog configuration
middleware/logging_middleware.pyRequest logging

Generation Process:

  1. Use MCP ref to get current structlog API
  2. Generate logging_config.py with:
    • Processor chain configuration
    • Renderer selection (JSON/Console)
    • Log level configuration
  3. Generate logging_middleware.py for FastAPI

Packages to Add:

  • structlog
  • python-json-logger (if JSON format)

Phase 5: Validate

Verify the configuration works.

Validation Steps:

  1. Check imports: Ensure all packages are available

    • .NET: dotnet list package | grep Serilog
    • Python: pip list | grep structlog
  2. Syntax check:

    • .NET: dotnet build --no-restore
    • Python: python -m py_compile core/logging_config.py
  3. Test log output:

    • Start application
    • Make test request
    • Verify log format matches configuration

Expected Log Format:

{
  "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:

{
  "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

Reference Links


Critical Rules

  • Use MCP ref/Context7 for current API — do not hardcode Serilog/structlog config from memory
  • Idempotent — if Serilog or structlog already configured, return status: "skipped" immediately
  • Environment-aware log levels — Debug for Development, Information for Production (never Warning default)
  • Always include correlation ID enrichment — required for distributed tracing
  • Return structured responsefiles_created, packages_added, registration_code for coordinator aggregation

Definition of Done

  • Context Store received and validated (stack, framework, version)
  • Best practices researched via MCP tools for target stack
  • User decisions collected (format, enrichment, sinks, log levels)
  • Configuration files generated (extensions/config + appsettings or Python modules)
  • Syntax validated (dotnet build or py_compile)
  • Structured JSON response returned to ln-770 coordinator

Version: 2.0.0 Last Updated: 2026-01-10

Source

git clone https://github.com/levnikolaevich/claude-code-skills/blob/master/ln-771-logging-configurator/SKILL.mdView on GitHub

Overview

ln-771-logging-configurator sets up structured JSON logging for .NET (Serilog) and Python (structlog) projects. It leverages the Context Store from ln-770 to tailor settings, researches current best practices with MCP, and generates framework-specific config files and code stubs. This enables consistent, enriched logs across environments with appropriate sinks and levels.

How This Skill Works

The skill starts by receiving the Context Store input (STACK, FRAMEWORK, FRAMEWORK_VERSION, PROJECT_ROOT, ENVIRONMENT). It then consults MCP references to identify recommended patterns (request middleware, enrichment, sinks, and environment-based level configurations) and prompts for user decisions on log format, enrichment fields, and sinks. Finally, it generates the .NET and Python configuration artifacts (including Extensions/LoggingExtensions.cs, appsettings.json variants, and core/logging_config.py plus middleware) and adds the necessary packages to implement the chosen setup.

When to Use It

  • Starting a new project that requires structured, production-ready logs.
  • Migrating an existing app from unstructured or semi-structured logging to JSON logs.
  • Standardizing logging across .NET and Python services within a microservices stack.
  • Configuring environment-specific log levels and sinks (Console/File/Seq/Elasticsearch) for prod or dev.
  • Adding correlation IDs and user context to logs to improve traceability.

Quick Start

  1. Step 1: Provide Context Store inputs (STACK, FRAMEWORK, FRAMEWORK_VERSION, PROJECT_ROOT, ENVIRONMENT) or allow auto-detection.
  2. Step 2: Choose log format, enrichment fields, and sinks based on Phase 3 decisions.
  3. Step 3: Run generation to create .NET and Python config files and install required packages.

Best Practices

  • Prefer JSON format for production and reserve Pretty/Colored for development debugging.
  • Always enable enrichment fields like correlationId, userId, requestPath, and responseTime by default.
  • Configure log sinks thoughtfully (Console, File with rotation, Seq, Elasticsearch) and enable rotation where appropriate.
  • Align log levels by environment to avoid flooding production logs with debug data.
  • Validate the generated configuration in a dev environment before promoting to production.

Example Use Cases

  • ASP.NET Core API using Serilog to emit JSON logs to Seq with correlation IDs.
  • FastAPI service using structlog to send structured logs to Elasticsearch for central analysis.
  • Monorepo services sharing a single logging configuration across .NET and Python components.
  • Migrating legacy logs to JSON with enrichment and environment-based level controls.
  • Containerized microservices with consistent structured logging to Console and Seq.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers