Logger

class · namespace z3n7 · source Essentials/Logger.cs

public class Logger

Writes messages to the ZennoPoster log. Header fields are switched on by substrings of the cfgLog project variable: acc (account), time (project age), port (instance port), caller (calling member), wrap (print the header at all), force (ignore the level filter).

Constructors

Logger

public Logger(IZennoPosterProjectModel project, Instance instance = null, LogLevel logLevel = LogLevel.Info, string classEmoji = null)

source

Creates a logger bound to a ZennoPoster project. The minimum level is taken from the logLevel project variable when it parses as LogLevel; otherwise Debug when debug is True; otherwise the logLevel argument.

Parameter Description
instance Not used; kept for compatibility.
logLevel Minimum level when the project variables do not set one.
classEmoji Value of Emoji.
public Logger(LogLevel logLevel = LogLevel.Info, string classEmoji = null)

source

Creates a logger without a ZennoPoster project. It has nowhere to write, so every message is dropped; thrw does not throw either.

Parameter Description
logLevel Minimum level.
classEmoji Value of Emoji.

Properties

Emoji

public string Emoji { get; set; }

source

Prefix shown in brackets before every message, e.g. the class marker.

Methods

ClearCache

public static void ClearCache(IZennoPosterProjectModel project)

source

Does nothing. Kept for compatibility: the logger no longer caches instances.

Debug

public void Debug(object msg, [CallerMemberName] string caller = "")

source

Writes a message at Debug level.

Error

public void Error(object msg, [CallerMemberName] string caller = "", bool thrw = false)

source

Writes an error. Errors are always written regardless of the minimum level.

Parameter Description
thrw Throw an Exception with the message after writing.

Get

public static Logger Get(IZennoPosterProjectModel project, Instance instance = null)

source

Creates a logger for the project with default settings.

Info

public void Info(object msg, [CallerMemberName] string caller = "")

source

Writes a message at Info level.

Send

public void Send(object toLog, [CallerMemberName] string caller = "", bool show = false, bool thrw = false, bool toZp = true, int cut = 0, LogLevel level = LogLevel.Info, LogType type = LogType.Info, LogColor color = LogColor.Default)

source

Writes a message. Messages below the minimum level are dropped unless show is true or cfgLog contains force. The ZennoPoster log type follows the level; text containing !W or !E is logged as a warning or an error.

Parameter Description
toLog Message; ToString() is used, null is written as "null".
caller Filled in by the compiler with the calling member name.
show Write even if below the minimum level.
thrw After writing to the ZennoPoster log, throw an Exception with the message. Only when the logger has a project and toZp is true.
toZp Write to the ZennoPoster log.
cut When the message has more than this many line breaks, join it into one line. 0 keeps it as is.
level Severity used for filtering.
type ZennoPoster log type; overridden by level Warning/Error and by the !W/!E markers.
color ZennoPoster log color.

Warn

public void Warn(object msg, [CallerMemberName] string caller = "", bool show = false, bool thrw = false)

source

Writes a warning.

Parameter Description
show Write even if below the minimum level.
thrw Throw an Exception with the message after writing.

WithInstance

public Logger WithInstance(Instance instance)

source

Returns a copy of this logger. Kept for compatibility: the instance is not used.