Avalonia Code OnlyItaliano

API › RAVAL

RLog class

public static class RLog

The log of the application: one for the whole program.

Properties

static RLogLevel Level { get; set; }

The least important level written (Info: no Debug, no Trace).

static bool Console { get; set; }

Whether the lines go also to the console.

static bool Colors { get; set; }

Whether the console lines are colored: the time dimmed, the level and the text in their colors (true).

static bool TrueColor { get; set; }

Whether the console shows the exact colors (ANSI 24 bit) instead of the nearest of its 16: true by itself in Windows Terminal and in the terminals that set COLORTERM=truecolor.

static string File { get; }

The log file ("" for none).

static long MaxBytes { get; set; }

The size beyond which the file rotates, bytes (10 MB).

static int MaxFiles { get; set; }

How many files are kept, the current one included (5).

static int RecentLines { get; set; }

How many lines Recent keeps (2000).

static bool Running { get; }

Whether the log has been started and not stopped.

Methods

static void Start(string app, string version, string file = null)

Starts the log: the thread that writes, the file (created with its folder; null or "" for none) and the first line with name, version, computer, operating system, .NET and process id.

static string StartLine(string app, string version)

The line that opens every run of a program in the log.

static void Stop()

Writes what is left in the queue, then closes the file.

static void Flush(int timeoutMs = 5000)

Waits until every line logged so far is written (tests, before a crash dump).

static void CatchUnhandled()

Also logs the exceptions nobody catches: those of any thread (AppDomain) and those of tasks whose result nobody reads.

static void Error(string text)

A line of level Error.

static void Error(string text, Exception e)

A line of level Error with the exception and its stack.

static void Warning(string text)

A line of level Warning.

static void Info(string text)

A line of level Info.

static void Info(string text, Color color)

A line of level Info in a color of its own (a phase, a device, a result).

static void Info(string text, string color)

A line of level Info in an HTML color: «#2b8a3e».

static void Debug(string text)

A line of level Debug.

static void Debug(string text, Color color)

A line of level Debug in a color of its own.

static void Trace(string text)

A line of level Trace.

static void Trace(string text, Color color)

A line of level Trace in a color of its own.

static bool Enabled(RLogLevel level)

Whether a line of this level would be written (to skip building costly texts).

static void Add(RLogLevel level, string text, Color? color = null)

A line of the given level. Before Start, or after Stop, the line goes only to Recent and to the debugger output: nothing is lost silently.

static RLogEntry[] Recent()

The last lines (at most RecentLines), oldest first.

static void ClearRecent()

Forgets the lines kept in memory (the file stays).

static ConsoleColor Nearest(Color c)

The console color nearest to an RGB color (for consoles without 24 bit colors).

static string Numbered(string file, int n)

The name of the n-th old file: «log/app.log», 2 → «log/app.2.log».

Events

event Action<RLogEntry> Written

Every line written, on the thread of the log (not the UI thread: a window moves it with the Dispatcher, as RLogView does).