This site provides a machine-readable index at /llms.txt.

Skip to main content Skip to navigation

DiagnosticContext Pennington.Diagnostics

Scoped service that accumulates diagnostics for a single HTTP request. Registered as scoped in DI — fresh instance per request, no thread-safety needed.

Properties

Diagnostics System.Collections.Generic.IReadOnlyList<Pennington.Diagnostics.Diagnostic>
Diagnostics accumulated for the current request, in insertion order.
HasAny bool
True when at least one diagnostic has been recorded.
HasErrors bool
True when at least one recorded diagnostic has Error severity.

Methods

Add

#
public void Add(Diagnostic diagnostic);

Appends a pre-built diagnostic to the context.

Parameters

diagnostic Diagnostic

AddError

#
public void AddError(string message, string? source = null);

Records an error-severity diagnostic with the given message and optional source label.

Parameters

message string
source string? (optional)

AddWarning

#
public void AddWarning(string message, string? source = null);

Records a warning-severity diagnostic with the given message and optional source label.

Parameters

message string
source string? (optional)

Pennington.Diagnostics.DiagnosticContext

namespace Pennington.Diagnostics;

/// Scoped service that accumulates diagnostics for a single HTTP request. Registered as scoped in DI — fresh instance per request, no thread-safety needed.
public class DiagnosticContext
{
    /// Appends a pre-built diagnostic to the context.
    
public void Add(Diagnostic diagnostic);
/// Records an error-severity diagnostic with the given message and optional source label.
public void AddError(string message, string? source = null);
/// Records a warning-severity diagnostic with the given message and optional source label.
public void AddWarning(string message, string? source = null);
/// Diagnostics accumulated for the current request, in insertion order.
public IReadOnlyList<Diagnostic> Diagnostics => _diagnostics;
/// True when at least one diagnostic has been recorded.
public bool HasAny => _diagnostics.Count > 0;
/// True when at least one recorded diagnostic has Error severity.
public bool HasErrors => _diagnostics.Exists(d => d.Severity is DiagnosticSeverity.Error);
}