Class RepeatingFaultLog
Logs a fault that may repeat every frame or tick without flooding the log.
public sealed class RepeatingFaultLog
- Inheritance
-
RepeatingFaultLog
- Inherited Members
Remarks
The server isolates each unit of repeating work (a behaviour's update, a periodic callback, an NPC brain, a weather scene) in its own try/catch so one failure cannot stop the rest. Isolation alone turns a deterministic throw into a full stack trace on every pass: 60 a second from a behaviour, 1,500 a second from fifty NPCs sharing a broken archetype. That drowns the first trace, which is the only one anyone needs.
One instance per unit of work. The first failure, and any failure whose exception type or message differs from the last, is logged in full. Identical repeats are counted and summarised at most once per SummaryIntervalSeconds. A success after failures logs one recovery line with the count, so a transient fault reads as transient.
Not thread-safe: each instance belongs to the thread that runs its unit of work, which for every current caller is the main thread.
Constructors
RepeatingFaultLog(string, string, double)
Creates a fault log for one unit of work.
public RepeatingFaultLog(string category, string subject, double summaryIntervalSeconds = 10)
Parameters
categorystringLog category, usually the owning system's name.
subjectstringWhat failed, e.g. a behaviour or callback name. Included in every line.
summaryIntervalSecondsdoubleSeconds between summaries of an identical fault.
Fields
DefaultSummaryIntervalSeconds
Default seconds between summaries of an identical repeating fault.
public const double DefaultSummaryIntervalSeconds = 10
Field Value
Properties
ConsecutiveFailures
Failures since the last success. Zero while the unit of work is healthy.
public int ConsecutiveFailures { get; }
Property Value
SummaryIntervalSeconds
Seconds between summaries of an identical repeating fault.
public double SummaryIntervalSeconds { get; }
Property Value
Methods
Record(Exception, double, out int)
Records a failure and decides what to log. Pure bookkeeping, so the rule is testable without a logger; Report(Exception, double) is the logging wrapper.
public RepeatingFaultLog.Decision Record(Exception ex, double now, out int repeats)
Parameters
exExceptionThe exception.
nowdoubleMonotonic time in seconds.
repeatsintFor LogSummary, the repeats being summarised (this one included); otherwise 0.
Returns
RecordSuccess()
Records a success. Returns the failure count it ends, or 0 if the unit was already healthy.
public int RecordSuccess()
Returns
Report(Exception, double)
Records a failure and logs it according to Record(Exception, double, out int).
public void Report(Exception ex, double now)
Parameters
ReportSuccess()
Records a success and logs a recovery line if it ends a run of failures.
public void ReportSuccess()