Class Logger
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
LogFolderPath
Returns the path to the folder where file logs are saved
public static string LogFolderPath { get; set; }
Property Value
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
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
RetainDays
Retain policy. How many days to retain in the storage medium. Defaults to 7
public static int RetainDays { get; set; }
Property Value
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
Settings
Settings
public static LogGlobalSettings Settings { get; }
Property Value
Methods
CreateSource(string)
Creates and returns a source
public static LogSource CreateSource(string Name)
Parameters
Namestring
Returns
Debug(string)
Logs a debug level message
public static void Debug(string Text)
Parameters
Textstring
Debug(string, string)
Logs a debug level message
public static void Debug(string EventId, string Text)
Parameters
Debug(string, string, string)
Logs a debug level message
public static void Debug(string Source, string EventId, string Text)
Parameters
Debug(string, string, string, string)
Logs a debug level message
public static void Debug(string Source, string ScopeId, string EventId, string Text)
Parameters
Error(Exception)
Logs an error message
public static void Error(Exception Ex)
Parameters
ExException
Error(string)
Logs an error message
public static void Error(string Text)
Parameters
Textstring
Error(string, Exception)
Logs an error message
public static void Error(string EventId, Exception Ex)
Parameters
Error(string, string)
Logs an error message
public static void Error(string EventId, string Text)
Parameters
Error(string, string, Exception)
Logs an error message
public static void Error(string Source, string EventId, Exception Ex)
Parameters
Error(string, string, string)
Logs an error message
public static void Error(string Source, string EventId, string Text)
Parameters
Error(string, string, string, Exception)
Logs an error message
public static void Error(string Source, string ScopeId, string EventId, Exception Ex)
Parameters
Error(string, string, string, string)
Logs an error message
public static void Error(string Source, string ScopeId, string EventId, string Text)
Parameters
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.
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
TextstringParamsDictionary<string, object>
Returns
GetAsJson(LogEntry)
Returns a string representation of a specified entry.
public static string GetAsJson(LogEntry Entry)
Parameters
EntryLogEntry
Returns
GetAsLine(LogEntry)
Returns a string representation of a specified entry.
public static string GetAsLine(LogEntry Entry)
Parameters
EntryLogEntry
Returns
GetAsList(LogEntry)
Returns a string representation of a specified entry.
public static string GetAsList(LogEntry Entry)
Parameters
EntryLogEntry
Returns
GetLineCaptions()
Returns a string with the captions of the log information, property formatted, i.e. right padded with spaces.
public static string GetLineCaptions()
Returns
Info(string)
Logs an info level message
public static void Info(string Text)
Parameters
Textstring
Info(string, string)
Logs an info level message
public static void Info(string EventId, string Text)
Parameters
Info(string, string, string)
Logs an info level message
public static void Info(string Source, string EventId, string Text)
Parameters
Info(string, string, string, string)
Logs an info level message
public static void Info(string Source, string ScopeId, string EventId, string Text)
Parameters
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
SourcestringScopeIdstringEventIdstringLevelLogLevelExceptionExceptionTextstringParamsDictionary<string, object>
Log(LogEntry)
Passes the log information to each listener.
public static void Log(LogEntry Info)
Parameters
InfoLogEntry
Trace(string)
Logs a trace level message
public static void Trace(string Text)
Parameters
Textstring
Trace(string, string)
Logs a trace level message
public static void Trace(string EventId, string Text)
Parameters
Trace(string, string, string)
Logs a trace level message
public static void Trace(string Source, string EventId, string Text)
Parameters
Trace(string, string, string, string)
Logs a trace level message
public static void Trace(string Source, string ScopeId, string EventId, string Text)
Parameters
Warn(string)
Logs a warn level message
public static void Warn(string Text)
Parameters
Textstring
Warn(string, string)
Logs a warn level message
public static void Warn(string EventId, string Text)
Parameters
Warn(string, string, string)
Logs a warn level message
public static void Warn(string Source, string EventId, string Text)
Parameters
Warn(string, string, string, string)
Logs a warn level message
public static void Warn(string Source, string ScopeId, string EventId, string Text)