Skip to content

Class CrashHandler

Namespace: Apogee.Core.Diagnostics
Assembly: Apogee.Core.dll

Writes a crash report when an exception ends the program, and one for the previous run when it did not end cleanly. It sees managed exceptions only ( and unobserved task exceptions): a crash in native code kills the process without running any managed code, and is found on the next start by , from the marker the dead run left (see ). Reports are plain text files named crash-*.txt; the newest twenty are kept.

public static class CrashHandler

Inheritance

object ← CrashHandler

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Methods

CheckPreviousRun(string)

The start of a run: the markers that earlier runs left in logDirectory (see ) whose process is gone are runs that did not end cleanly. Each gets a report of kind with the end of its log, and its marker is removed. A marker of a process that still runs (another instance) is left alone.

public static int CheckPreviousRun(string logDirectory)

Parameters

logDirectory string

Returns

int

The number of reports written.

Install(string, RecentLogSink)

Starts watching for unhandled exceptions. Reports go to reportDirectory ( moves them), with the lines recent kept (add it to yourself). The hooks are made once; calling again only replaces the folder and the sink.

public static void Install(string reportDirectory, RecentLogSink recent)

Parameters

reportDirectory string

recent RecentLogSink

SetContext(string, string)

Adds a line to the reports (key: value): the game, its version, the GPU. A key set again is replaced.

public static void SetContext(string key, string value)

Parameters

key string

value string

SetLogFile(IDisposable?)

The log file of the run: it is closed (and its marker removed) when an exception ends the program, since the crash has been reported by then. Null: none.

public static void SetLogFile(IDisposable? logFile)

Parameters

logFile IDisposable?

SetReportDirectory(string)

Moves the reports to another folder, once the game's own is known.

public static void SetReportDirectory(string reportDirectory)

Parameters

reportDirectory string

WriteReport(CrashKind, Exception?)

Writes a report now, with the lines 's sink kept, and keeps the newest twenty files of the folder. Never throws.

public static string? WriteReport(CrashKind kind, Exception? exception)

Parameters

kind CrashKind

exception Exception?

Returns

string?

The path of the report; null when there is no folder yet, or the report could not be written (a line on stderr says why).