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
DiagnosticsIReadOnlyList<Diagnostic>- Diagnostics accumulated for the current request, in insertion order.
HasAnybool- True when at least one diagnostic has been recorded.
HasErrorsbool- True when at least one recorded diagnostic has
Errorseverity.
Methods
Add
#public void Add(Diagnostic diagnostic)
Appends a pre-built diagnostic to the context.
Parameters
diagnosticDiagnostic
AddError
#public void AddError(string message, string source = null)
Records an error-severity diagnostic with the given message and optional source label.
Parameters
messagestringsourcestring
AddInfo
#public void AddInfo(string message, string source = null)
Records an info-severity diagnostic with the given message and optional source label.
Parameters
messagestringsourcestring
AddWarning
#public void AddWarning(string message, string source = null)
Records a warning-severity diagnostic with the given message and optional source label.
Parameters
messagestringsourcestring
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; }
}