Table of Contents

Class Logger

Namespace
Tripous.Logging
Assembly
Tripous.Logging.dll

Represents an object that handles log information.

A code can instruct Logger to log a bit of information by calling one of the various Log() methods. Then the Logger notifies all ILogListener objects subscribed to it by calling the ILogListener.ProcessLog() of each one passing an LogInfo object that represents the log information.

The Logger doesn't actually logs the information in any medium. Instead it relies in that some one of its ILogListener subscribers is capable of doing that.

Any thread can call any of the Log() methods of the Logger.

CAUTION: The Logger calls its Listeners asynchronously, that is from inside a thread. Thus Listeners should synchronize the ProcessLog() call. Controls need to check if InvokeRequired.

public static class Logger
Inheritance
Logger
Inherited Members

Properties

Active

When false no logs are recorded. Defaults to true.

public static bool Active { get; set; }

Property Value

bool

LogFolderPath

Returns the path to the folder where file logs are saved

public static string LogFolderPath { get; set; }

Property Value

string

MaxSizeKiloBytes

Retain policy. How many KB to allow a single log file to grow. Defaults to 512 KB

public static int MaxSizeKiloBytes { get; set; }

Property Value

int

MinLevel

The level of the accepted log. For a log info to be recorded its log level must be greater or equal to this level. See LogLevel enum for the numeric values of each level.

Defaults to Info.

public static LogLevel MinLevel { get; set; }

Property Value

LogLevel

RetainDays

Retain policy. How many days to retain in the storage medium. Defaults to 7

public static int RetainDays { get; set; }

Property Value

int

RetainPolicyCounter

After how many writes to check whether it is time to apply the retain policy. Defaults to 100

public static int RetainPolicyCounter { get; set; }

Property Value

int

Settings

Settings

public static LogGlobalSettings Settings { get; }

Property Value

LogGlobalSettings

Methods

CreateSource(string)

Creates and returns a source

public static LogSource CreateSource(string Name)

Parameters

Name string

Returns

LogSource

Debug(string)

Logs a debug level message

public static void Debug(string Text)

Parameters

Text string

Debug(string, string)

Logs a debug level message

public static void Debug(string EventId, string Text)

Parameters

EventId string
Text string

Debug(string, string, string)

Logs a debug level message

public static void Debug(string Source, string EventId, string Text)

Parameters

Source string
EventId string
Text string

Debug(string, string, string, string)

Logs a debug level message

public static void Debug(string Source, string ScopeId, string EventId, string Text)

Parameters

Source string
ScopeId string
EventId string
Text string

Error(Exception)

Logs an error message

public static void Error(Exception Ex)

Parameters

Ex Exception

Error(string)

Logs an error message

public static void Error(string Text)

Parameters

Text string

Error(string, Exception)

Logs an error message

public static void Error(string EventId, Exception Ex)

Parameters

EventId string
Ex Exception

Error(string, string)

Logs an error message

public static void Error(string EventId, string Text)

Parameters

EventId string
Text string

Error(string, string, Exception)

Logs an error message

public static void Error(string Source, string EventId, Exception Ex)

Parameters

Source string
EventId string
Ex Exception

Error(string, string, string)

Logs an error message

public static void Error(string Source, string EventId, string Text)

Parameters

Source string
EventId string
Text string

Error(string, string, string, Exception)

Logs an error message

public static void Error(string Source, string ScopeId, string EventId, Exception Ex)

Parameters

Source string
ScopeId string
EventId string
Ex Exception

Error(string, string, string, string)

Logs an error message

public static void Error(string Source, string ScopeId, string EventId, string Text)

Parameters

Source string
ScopeId string
EventId string
Text string

FormatParams(string, Dictionary<string, object>)

Formats the specified params into a placeholder containing text. It also returns a dictionary of the specified params for use by structured log listeners.

The specified text may contain placeholders. Placeholders are replaced based in their order, NOT in their content. The content of a placeholder becomes a key in the returned dictionary.

string Text = "Customer {CustomerId} order {OrderId} is completed.";
var ParamsDictionary = FormatParams(ref Text, new { CustomerId = 123, OrderId = 456 });
public static string FormatParams(string Text, Dictionary<string, object> Params)

Parameters

Text string
Params Dictionary<string, object>

Returns

string

GetAsJson(LogEntry)

Returns a string representation of a specified entry.

public static string GetAsJson(LogEntry Entry)

Parameters

Entry LogEntry

Returns

string

GetAsLine(LogEntry)

Returns a string representation of a specified entry.

public static string GetAsLine(LogEntry Entry)

Parameters

Entry LogEntry

Returns

string

GetAsList(LogEntry)

Returns a string representation of a specified entry.

public static string GetAsList(LogEntry Entry)

Parameters

Entry LogEntry

Returns

string

GetLineCaptions()

Returns a string with the captions of the log information, property formatted, i.e. right padded with spaces.

public static string GetLineCaptions()

Returns

string

Info(string)

Logs an info level message

public static void Info(string Text)

Parameters

Text string

Info(string, string)

Logs an info level message

public static void Info(string EventId, string Text)

Parameters

EventId string
Text string

Info(string, string, string)

Logs an info level message

public static void Info(string Source, string EventId, string Text)

Parameters

Source string
EventId string
Text string

Info(string, string, string, string)

Logs an info level message

public static void Info(string Source, string ScopeId, string EventId, string Text)

Parameters

Source string
ScopeId string
EventId string
Text string

Log(string, string, string, LogLevel, Exception, string, Dictionary<string, object>)

Passes the log information to each listener.

NOTE: For how params are formatted into the specified text see FormatParams(string, Dictionary<string, object>)

public static void Log(string Source, string ScopeId, string EventId, LogLevel Level, Exception Exception, string Text, Dictionary<string, object> Params)

Parameters

Source string
ScopeId string
EventId string
Level LogLevel
Exception Exception
Text string
Params Dictionary<string, object>

Log(LogEntry)

Passes the log information to each listener.

public static void Log(LogEntry Info)

Parameters

Info LogEntry

Trace(string)

Logs a trace level message

public static void Trace(string Text)

Parameters

Text string

Trace(string, string)

Logs a trace level message

public static void Trace(string EventId, string Text)

Parameters

EventId string
Text string

Trace(string, string, string)

Logs a trace level message

public static void Trace(string Source, string EventId, string Text)

Parameters

Source string
EventId string
Text string

Trace(string, string, string, string)

Logs a trace level message

public static void Trace(string Source, string ScopeId, string EventId, string Text)

Parameters

Source string
ScopeId string
EventId string
Text string

Warn(string)

Logs a warn level message

public static void Warn(string Text)

Parameters

Text string

Warn(string, string)

Logs a warn level message

public static void Warn(string EventId, string Text)

Parameters

EventId string
Text string

Warn(string, string, string)

Logs a warn level message

public static void Warn(string Source, string EventId, string Text)

Parameters

Source string
EventId string
Text string

Warn(string, string, string, string)

Logs a warn level message

public static void Warn(string Source, string ScopeId, string EventId, string Text)

Parameters

Source string
ScopeId string
EventId string
Text string