This documentation is also published as Markdown for efficient machine reading: the whole site is indexed at /llms.txt, and every page has a clean Markdown copy under /_llms/. These are generated from the same source and cost far fewer tokens to read than this rendered HTML.

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 IReadOnlyList<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

AddInfo

#
public void AddInfo(string message, string source = null)

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

Parameters

message string
source string

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

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 an info-severity diagnostic with the given message and optional source label.
public void AddInfo(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 { get; }
/// True when at least one diagnostic has been recorded.
public bool HasAny { get; }
/// True when at least one recorded diagnostic has Error severity.
public bool HasErrors { get; }
}