Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

dotnet-source-gen-logging

/dotnet-source-gen-logging

Przekształca logowanie na generator źródeł LoggerMessage, aby uzyskać wydajne logowanie zgodne z AOT i ustrukturyzowane logi.

Repozytorium
claude ↗
Licencja
MIT
Ostatnia zmiana repozytorium
15.09.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
1
Przestarzałość

Brak sygnałów. Repozytorium zmienione 15.09.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Przekształca logowanie na generator źródeł LoggerMessage, aby uzyskać wydajne logowanie zgodne z AOT i ustrukturyzowane logi.

Wyzwalacze z opisu

LoggerMessage,logging source generator,high-performance logging,optimize logging,AOT logging,structured logging source gen.
Oryginalny opis (EN)

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.

Jak działa

  1. When to Use
  2. Steps
  3. Key Notes
  4. Example Conversion
Sekcje z nagłówków SKILL.md, w oryginale · 109 linii, 449 słów
Podgląd SKILL.md
---
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
metadata:
  author: Im5tu
  version: "1.0"
  repositoryUrl: https://github.com/im5tu/dotnet-skills
allowed-tools: Bash(dotnet:*), Read, Edit, Write, Glob, Grep, AskUserQuestion
---

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);
```

Wersje

W bazie nie ma innych skilli o nazwie dotnet-source-gen-logging.

Migawka bazy z 13.11.2026 · wersja paczki 625977d2ba42 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100dotnet-aot-analysis
    Analizuje i konfiguruje projekt lub rozwiązanie .NET pod kątem zgodności z Native AOT, koordynując skille generatorów źródeł i stosując ustawienia AOT, w tym trimming.
  • 100dotnet-source-gen-options-validation
    Przekształca walidację opcji na generator źródeł działający w czasie kompilacji, zgodny z AOT i bez refleksji, jako zamiennik ValidateDataAnnotations.
  • 100dotnet-source-generated-logging
    Pisze logi .NET generatorem źródeł LoggerMessage dla wywołań ILogger: szablony komunikatów, poziomy logowania, identyfikatory zdarzeń, logowanie wyjątków i zakresy.
  • 100extensions-logging
    Wspiera logowanie w Microsoft.Extensions.Logging: ILogger, generatory źródeł LoggerMessage, logi strukturalne z identyfikatorami zdarzeń, filtrowanie i wydajne wzorce logowania.
  • 84using-generated-regex
    Wdraża w .NET wyrażenia regularne generowane podczas kompilacji przez GeneratedRegexAttribute, dla wydajności i AOT.
  • 100dotnet-aot-compat
    Dostosowuje projekty .NET do Native AOT i trimmingu przez systematyczne usuwanie ostrzeżeń analizatora IL (IL2026, IL2070, IL3050), dodawanie adnotacji DynamicallyAccessedMembers i włączanie IsAotCompatible.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.