Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions docs/rules/WS0001.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@

## Cause

Extension methods on `IWitness<T>` that call `ILogger` with constant message templates incur per-call allocation and template parsing. Use `[LoggerMessage]` to eliminate both. On **net9.0+**, a source-generator interceptor optimizes these automatically; on **net8.0**, apply the code-fix suggestion.
Direct `ILogger` calls in `IWitness<T>` extension methods allocate and parse message templates at runtime. Use `[LoggerMessage]` to eliminate both (automatic on **net9.0+** via source-generator interceptor; manual on **net8.0**).

```csharp
public static void LogOrderPlaced(this IWitness<OrderService> witness, int orderId)
{
witness.Logger.LogInformation("Order {OrderId} placed", orderId); // ⚠️ WS0001
}
=> witness.Logger.LogInformation("Order {OrderId} placed", orderId); // ⚠️ WS0001
```

## How to Fix

**net9.0+/net10.0**: Optimized automatically—no action needed.
**net9.0+**: Automatic—no action needed (source-generator interceptor optimizes calls).

**net8.0**: Apply the code-fix suggestion or manually extract into `[LoggerMessage]`:
**net8.0**: Apply the code-fix or manually refactor:

```csharp
public static partial class OrderServiceLog
Expand All @@ -30,10 +28,10 @@ public static partial class OrderServiceLog
}
```

To suppress for performance-insensitive cases:
To suppress in performance-insensitive code:

```csharp
#pragma warning disable WS0001
witness.Logger.LogInformation("Startup message {Value}", value);
witness.Logger.LogInformation("Non-critical: {Value}", value);
#pragma warning restore WS0001
```