Agent skill
lang__logger_message
Adds structured, high-performance logging using LoggerMessage source generator. Use when adding logs to handlers, services, or middleware. Organizes logs by domain (Books, Users, etc.) in Infrastructure/Logging/Log.<Domain>.cs files.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/lang-logger-message
SKILL.md
All logging in BookStore MUST use the LoggerMessage source generator pattern for performance and consistency. Logs are organized by domain in separate partial classes.
Structure
Logs are organized in src/BookStore.ApiService/Infrastructure/Logging/Log.<Domain>.cs:
- Each domain (Books, Users, etc.) is a nested partial class inside
Log - Use appropriate log levels: Information, Warning, Error, Debug
- Include relevant parameters for structured logging
- Use descriptive method names in past tense for completed actions
Steps
-
Identify Domain
- Determine which domain your logging belongs to (Books, Authors, Users, etc.)
- Existing domains: Books, Authors, Publishers, Categories, Users, Email, Tenants, Notifications, Infrastructure, Maintenance, Seeding
- Create new domain file if needed:
Log.<YourDomain>.cs
-
Add Log Method
- Open or create
Infrastructure/Logging/Log.<Domain>.cs - Add a new partial method with
[LoggerMessage]attribute - Template: See templates/Log.Domain.cs for structure
- Include all relevant parameters for context
- Open or create
-
Choose Log Level
LogLevel.Information: Success operations, normal flowLogLevel.Warning: Validation failures, recoverable errors, suspicious activityLogLevel.Error: Exceptions, failures requiring attentionLogLevel.Debug: Detailed diagnostic information
-
Use in Code
- Inject
ILogger<YourClass>in constructor - Call:
Log.<Domain>.<MethodName>(logger, params...) - For errors: Exception parameter comes after logger, before other params
- Inject
Examples
Information Level:
[LoggerMessage(
Level = LogLevel.Information,
Message = "Book created successfully: Id={BookId}, Title={Title}")]
public static partial void BookCreated(
ILogger logger,
Guid bookId,
string title);
Error Level with Exception:
[LoggerMessage(
Level = LogLevel.Error,
Message = "Failed to create book: Title={Title}")]
public static partial void BookCreationFailed(
ILogger logger,
Exception ex,
string title);
Usage in Handler:
public class CreateBookHandler(ILogger<CreateBookHandler> logger)
{
public Task Handle(CreateBook command)
{
try
{
// ... create book logic ...
Log.Books.BookCreated(logger, bookId, title);
}
catch (Exception ex)
{
Log.Books.BookCreationFailed(logger, ex, title);
throw;
}
}
}
Common Patterns
Operation Flow:
- Operation starting:
<Entity>Creating,<Entity>Updating,<Entity>Deleting - Operation success:
<Entity>Created,<Entity>Updated,<Entity>Deleted - Operation failure:
<Entity>CreationFailed,<Entity>UpdateFailed, etc.
Validation/Security:
- Use
LogLevel.Warningfor validation failures, authentication issues - Include enough context to debug without sensitive data
Correlation:
- Include CorrelationId when starting operations for request tracing
- Include entity IDs, versions, relevant metadata
Related Skills
Prerequisites:
- Understanding of the domain you're logging for
See Also:
/wolverine__create_operation- Uses logging in command handlers/wolverine__update_operation- Uses logging in update handlers/wolverine__delete_operation- Uses logging in delete handlersdocs/architecture.md- System architecture and patterns- Existing domain files in
src/BookStore.ApiService/Infrastructure/Logging/
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?