Skip to content
Agentmart
Submit a tool

dotnet-source-gen-logging

Converts logging to use the LoggerMessage source generator for high-performance, AOT-compatible logging.

Skill by Im5tu

IndexedMIT★ 6
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/im5tu-dotnet-source-gen-logging

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Converts logging to use the LoggerMessage source generator for high-performance, AOT-compatible logging. Also use when the user mentions "LoggerMessage," "logging source generator," "high-performance logging," "optimize logging," "AOT logging," or "structured logging source gen." For full AOT analysis, see dotnet-aot-analysis.

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/dotnet-source-gen-logging

Tools it pre-approves 7

From allowed-tools in SKILL.md: the agent may use these without asking you each time.

  • Bash(dotnet:*),
  • Read,
  • Edit,
  • Write,
  • Glob,
  • Grep,
  • AskUserQuestion

What's inside

Skill name
dotnet-source-gen-logging
Description
Converts logging to use the LoggerMessage source generator for high-performance, AOT-compatible logging. Also use when the user mentions "LoggerMessage," "logging source generator," "high-performance logging," "optimize logging," "AOT logging," or "structured logging source gen." For full AOT analysis, see dotnet-aot-analysis.
License
MIT
Allowed tools
Bash(dotnet:*),, Read,, Edit,, Write,, Glob,, Grep,, AskUserQuestion
Metadata
author: Im5tu · version: 1.0 · repositoryUrl: https://github.com/im5tu/dotnet-skills
Instructions
109 lines in SKILL.md · view on GitHub

Before installing

  • Pre-approves some shell commands

Files (1)

  • SKILL.md

SKILL.md (first lines)

Convert existing logging calls to use the `LoggerMessage` source generator for AOT-compatible logging with no boxing overhead and compile-time template parsing.

## When to Use

- Optimizing logging performance in hot paths
- Preparing for Native AOT deployment
- Organizing scattered log messages into logical groupings
- Standardizing EventIds across the codebase

## Steps

1. **Find ILogger usages and logging calls**
   - Search for `ILogger` field/parameter declarations
   - Find all logging calls: `LogInformation`, `LogWarning`, `LogError`, `LogDebug`, `LogTrace`, `LogCritical`
   - Note the log message templates and parameters

2. **Organize into logical groupings by domain**
   - Group related log messages by their functional area, eg:
     - `LoggingValidationExtensions` - validation-related logs
     - `LoggingAuthenticationExtensions` - auth-related logs
     - `LoggingDatabaseExtensions` - database-related logs
     - `LoggingHttpExtensions` - HTTP-related logs
     - `LoggingCacheExtensions` - caching-related logs
     - `LoggingMessagingExtensions` - messaging/queue-related logs

3. **Create partial static classes with extension methods**
   ```csharp
   public static partial class LoggingValidationExtensions
   {
       [LoggerMessage(
           EventId = 1001,
           Level = LogLevel.Warning,
           Message = "Validation failed for {EntityType}: {Errors}")]
       public static partial void ValidationFailed(
           this ILogger logger, string entityType, string errors);
   }
   ```

4. **Use EventId ranges per category**
   - 1000-1999: Validation
   - 2000-2999: Authentication
   - 3000-3999: Database
   - 4000-4999: HTTP
   - 5000-5999: Cache
   - 6000-6999: Messaging
   - 7000-7999: General/Application

5. **Replace inline logging calls with extension method calls**
   - Before: `_logger.LogWarning("Validation failed for {entityType}: {errors}", type, errs)`
   - After: `_logger.ValidationFailed(type, errs)`

6. **Verify with build**
   ```bash
   dotnet build
   ```

7. **If build fails**, review errors:
   - Missing `using` statements for the extension class namespace
   - Parameter type mismatches
   - Duplicate EventIds

8. **Report results**:
   - List all created extension classes
   - Show count of converted log messages per category
   - Confirm build status

## Key Notes

- **Requires .NET 6+** - the source generator is built into the SDK
- **Avoids boxing** - value types are not boxed when passed to the generated methods
- **Template parsed once** - message template is parsed at compile time, not runtime
- **Use PascalCase for placeholders** - `{EntityType}` not `{entityType}` (matching is case-insensitive, but PascalCase is the recommended convention)
- **Extension methods** - allows fluent `logger.MethodName()` syntax
- **Partial classes** - required for source generator to emit the implementation

## Example Conversion

Before:
```csharp
_logger.LogInformation("User {UserId} logged in from {IpAddress}", userId, ip);
_logger.LogWarning("Failed login attempt for {Username}", username);
```

After:
```csharp
// In LoggingAuthenticationExtensions.cs
public static partial class LoggingAuthenticationExtensions
{
    [LoggerMessage(
        EventId = 2001,
        Level = LogLevel.Information,
        Message = "User {UserId} logged in from {IpAddress}")]
    public static partial void UserLoggedIn(
        this ILogger logger, string userId, string ipAddress);

    [LoggerMessage(
        EventId = 2002,
        Level = LogLevel.Warning,
        Message = "Failed login attempt for {Username}")]
    public static partial void FailedLoginAttempt(
        this ILogger logger, string username);
}

// Usage
_logger.UserLoggedIn(userId, ip);
_logger.FailedLoginAttempt(username);
```

From Im5tu/claude, MIT.

More from Im5tu/claude

Signals

Stars
6
Forks
3
Open issues
0
Last commit (this folder)
Aug 21, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

Version
1.0
License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from Im5tu

Cite this page

dotnet-source-gen-logging skill. Agent Mart. https://agentmart.dev/skills/im5tu-dotnet-source-gen-logging (last updated 2026-10-24)