Skip to main content
ai-slop/csharp-console-leftovermanual fix

Console leftover in C#.

`Console.Write`/`WriteLine` in library code, or `Debug`/`Trace` write calls in shipped code. Usually output left over from debugging.

Flagged shape and clean shape.

Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.

csharp-console-leftover.cs
✗ Flagged
public decimal CalculateTax(Order order)
{
    Console.WriteLine($"Calculating tax for {order.Id}");
    var rate = _rates.For(order.Region);
    Debug.WriteLine(rate);
    return order.Subtotal * rate;
}
Why this trips

Deterministic line match on masked source: flags `Debug.` and `Trace.` `Write`, `WriteLine`, `WriteIf`, and `WriteLineIf` calls, and `Console.Write`/`WriteLine` in projects that do not build an executable.

csharp-console-leftover.cs
✓ Clean
public decimal CalculateTax(Order order)
{
    var rate = _rates.For(order.Region);
    _logger.LogDebug("Tax rate {Rate} for order {OrderId}", rate, order.Id);
    return order.Subtotal * rate;
}
What changed

Remove the write, or route it through the project's `ILogger` at an appropriate level.

Agents check behavior by writing to the console, then leave the call in. In a library it writes to the host's stdout with no level, structure, or way to turn it off.

How this rule is justified.

Rule id

ai-slop/csharp-console-leftover

Enforcing engine

ai-slop

Detector strategy

Deterministic line match on masked source: flags `Debug.` and `Trace.` `Write`, `WriteLine`, `WriteIf`, and `WriteLineIf` calls, and `Console.Write`/`WriteLine` in projects that do not build an executable.

Legitimate code that is NOT flagged

`Console.Error`, Console output in executable projects (OutputType Exe or WinExe, or the Web, Worker, or BlazorWebAssembly SDKs), files marked `// aislop-worker`, and scripts, examples, docs, and other non-production paths are not flagged.

Evidence

Part of aislop's C# rule set. First-class C# support, including C#-specific AI-slop rules, arrived in aislop v0.14.1.