Class LoggerHelper
Extension methods that write log records through log4net. The records go to the appenders configured by Utils.Common.Logging.Logger (the log files) and to the Utils.Common.Logging.ILoggerListener instances added to it. For an ILoggerSource sender the record is written under the source's LoggerName and discarded when its level is below the effective level of the source (see GetLoggingLevel(ILoggerSource)). For any other sender it is written under the full name of the sender's type (or under the string itself when the sender is a string) with the Info level, so Debug records of such senders are discarded. Format strings use string.Format(string, params object[]) placeholders. The log4net logger is cached per sender and released when the sender is garbage collected.
public static class LoggerHelper
- Inheritance
-
objectLoggerHelper
Methods
DisposeLogger(object)
Drops the cached logger of the sender. Optional: the entry is also released when the sender is garbage collected.
public static void DisposeLogger(this object sender)
Parameters
senderobjectThe object whose logger to drop.
Exceptions
- ArgumentNullException
senderis null.
DisposeLogger(ILoggerSource)
Detaches the source from its parent (sets ParentLoggerSource to null) and drops its cached logger. The cached logger would also be released when the source is garbage collected; the detaching is what this call adds.
public static void DisposeLogger(this ILoggerSource sender)
Parameters
senderILoggerSourceThe source to release.
Exceptions
- ArgumentNullException
senderis null.
GetLoggingLevel(ILoggerSource)
Returns the effective level of the source: its own LoggingLevel, or, when that is Inherit, the level of the nearest ancestor that sets one; Info when none does.
public static LoggingLevel GetLoggingLevel(this ILoggerSource sender)
Parameters
senderILoggerSourceThe source to check.
Returns
- LoggingLevel
The effective level; never Inherit.
Exceptions
- ArgumentNullException
senderis null.
GetSources()
Returns a snapshot of the senders that currently have a cached logger, that is, have written a record and are still alive.
public static IEnumerable<object> GetSources()
Returns
- IEnumerable<object>
The senders.
IsDebug(ILoggerSource)
Returns whether the effective level of the source is Debug, so that expensive debug output can be skipped otherwise.
public static bool IsDebug(this ILoggerSource sender)
Parameters
senderILoggerSourceThe source to check.
Returns
- bool
true if Debug records of the source are written.
Exceptions
- ArgumentNullException
senderis null.
LogDebug(object, string, params object?[])
Writes a Debug record for a sender that is not an ILoggerSource. Such a sender's logger has the Info level, so the record is discarded unless the log4net configuration lowers it; prefer the ILoggerSource overloads.
public static void LogDebug(this object sender, string format, params object?[] args)
Parameters
senderobjectThe object that writes the record.
formatstringThe format string.
argsobject[]The format arguments.
Exceptions
- ArgumentNullException
formatis null.
LogDebug(ILoggerSource, string, Func<object>)
Writes a Debug record whose single format argument is computed by getArgs only when the effective
level of the source is Debug, so an expensive argument costs nothing otherwise.
public static void LogDebug(this ILoggerSource sender, string format, Func<object> getArgs)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
getArgsFunc<object>Returns the value for the
{0}placeholder.
Exceptions
- ArgumentNullException
formatis null.
LogDebug(ILoggerSource, string, object)
Writes a Debug record when the effective level of the source is Debug.
Added in ATAS 8.0.15.
public static void LogDebug(this ILoggerSource sender, string format, object arg0)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
Exceptions
- ArgumentNullException
formatis null.
LogDebug(ILoggerSource, string, object?, object?)
Writes a Debug record when the effective level of the source is Debug.
Added in ATAS 8.0.15.
public static void LogDebug(this ILoggerSource sender, string format, object? arg0, object? arg1)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
arg1objectThe second format argument.
Exceptions
- ArgumentNullException
formatis null.
LogDebug(ILoggerSource, string, object, object, object)
Writes a Debug record when the effective level of the source is Debug.
Added in ATAS 8.0.15.
public static void LogDebug(this ILoggerSource sender, string format, object arg0, object arg1, object arg2)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
arg1objectThe second format argument.
arg2objectThe third format argument.
Exceptions
- ArgumentNullException
formatis null.
LogDebug(ILoggerSource, string, params object?[])
Writes a Debug record when the effective level of the source is Debug.
public static void LogDebug(this ILoggerSource sender, string format, params object?[] args)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
argsobject[]The format arguments.
Exceptions
- ArgumentNullException
formatis null.
LogDebugCensored(ILoggerSource, string?, string, params object[])
Writes a Debug record in which every occurrence of sensitiveData is replaced with a placeholder
(see Utils.Common.Censorer.Censor(string, string); censoring works only while Utils.Common.Censorer.Enabled is set). The text is formatted
only when the effective level of the source is Debug.
Added in ATAS 8.0.15.
public static void LogDebugCensored(this ILoggerSource sender, string? sensitiveData, string format, params object[] args)
Parameters
senderILoggerSourceThe source that writes the record.
sensitiveDatastringThe password or token to hide; null, empty or shorter than 4 characters is not censored.
formatstringThe format string.
argsobject[]The format arguments.
Exceptions
- ArgumentNullException
formatis null.
LogDebugMultiCensored(ILoggerSource, string?, string?, string, params object[])
Writes a Debug record in which every occurrence of the two sensitive values is replaced with a placeholder (see Utils.Common.Censorer.CensorMultipleValues(string, params string[]); censoring works only while Utils.Common.Censorer.Enabled is set). The text is formatted only when the effective level of the source is Debug.
Added in ATAS 8.0.15.
public static void LogDebugMultiCensored(this ILoggerSource sender, string? sensitiveData1, string? sensitiveData2, string format, params object[] args)
Parameters
senderILoggerSourceThe source that writes the record.
sensitiveData1stringThe first value to hide; null or empty is ignored.
sensitiveData2stringThe second value to hide; null or empty is ignored.
formatstringThe format string.
argsobject[]The format arguments.
Exceptions
- ArgumentNullException
formatis null.
LogError(object, string, Exception, bool)
Writes message as an Error record with the exception attached, without formatting the message,
for a sender that is not an ILoggerSource.
public static void LogError(this object sender, string message, Exception excp, bool isVisible = true)
Parameters
senderobjectThe object that writes the record.
messagestringThe text of the record.
excpExceptionThe exception to attach.
isVisibleboolThe Utils.Common.Logging.LoggerItem.IsVisible value passed to the listeners; false keeps the record out of the platform's log panel while the log files still contain it.
Exceptions
- ArgumentNullException
messageis null.
LogError(object, string, params object?[])
Writes an Error record for a sender that is not an ILoggerSource, under the name of its type.
public static void LogError(this object sender, string format, params object?[] args)
Parameters
senderobjectThe object that writes the record.
formatstringThe format string.
argsobject[]The format arguments.
Exceptions
- ArgumentNullException
formatis null.
LogError(ILoggerSource, string, Exception, bool)
Writes message as an Error record with the exception attached, without formatting the message.
The listeners receive the exception message appended to the text.
public static void LogError(this ILoggerSource sender, string message, Exception excp, bool isVisible = true)
Parameters
senderILoggerSourceThe source that writes the record.
messagestringThe text of the record.
excpExceptionThe exception to attach.
isVisibleboolThe Utils.Common.Logging.LoggerItem.IsVisible value passed to the listeners; false keeps the record out of the platform's log panel while the log files still contain it.
Exceptions
- ArgumentNullException
messageis null.
LogError(ILoggerSource, string, object)
Writes an Error record unless the effective level of the source is higher.
Added in ATAS 8.0.15.
public static void LogError(this ILoggerSource sender, string format, object arg0)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
Exceptions
- ArgumentNullException
formatis null.
LogError(ILoggerSource, string, object, object)
Writes an Error record unless the effective level of the source is higher.
Added in ATAS 8.0.15.
public static void LogError(this ILoggerSource sender, string format, object arg0, object arg1)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
arg1objectThe second format argument.
Exceptions
- ArgumentNullException
formatis null.
LogError(ILoggerSource, string, object, object, object)
Writes an Error record unless the effective level of the source is higher.
Added in ATAS 8.0.15.
public static void LogError(this ILoggerSource sender, string format, object arg0, object arg1, object arg2)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
arg1objectThe second format argument.
arg2objectThe third format argument.
Exceptions
- ArgumentNullException
formatis null.
LogError(ILoggerSource, string, params object?[])
Writes an Error record unless the effective level of the source is higher.
public static void LogError(this ILoggerSource sender, string format, params object?[] args)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
argsobject[]The format arguments.
Exceptions
- ArgumentNullException
formatis null.
LogFatal(object, string, Exception, bool)
Writes message as a Fatal record with the exception attached, without formatting the message,
for a sender that is not an ILoggerSource.
public static void LogFatal(this object sender, string message, Exception ex, bool isVisible = true)
Parameters
senderobjectThe object that writes the record.
messagestringThe text of the record.
exExceptionThe exception to attach.
isVisibleboolThe Utils.Common.Logging.LoggerItem.IsVisible value passed to the listeners; false keeps the record out of the platform's log panel while the log files still contain it.
Exceptions
- ArgumentNullException
messageis null.
LogFatal(ILoggerSource, string, bool)
Writes message as a Fatal record without formatting it.
public static void LogFatal(this ILoggerSource sender, string message, bool isVisible = true)
Parameters
senderILoggerSourceThe source that writes the record.
messagestringThe text of the record.
isVisibleboolThe Utils.Common.Logging.LoggerItem.IsVisible value passed to the listeners; false keeps the record out of the platform's log panel while the log files still contain it.
Exceptions
- ArgumentNullException
messageis null.
LogFatal(ILoggerSource, string, Exception, bool)
Writes message as a Fatal record with the exception attached, without formatting the message.
public static void LogFatal(this ILoggerSource sender, string message, Exception ex, bool isVisible = true)
Parameters
senderILoggerSourceThe source that writes the record.
messagestringThe text of the record.
exExceptionThe exception to attach.
isVisibleboolThe Utils.Common.Logging.LoggerItem.IsVisible value passed to the listeners; false keeps the record out of the platform's log panel while the log files still contain it.
Exceptions
- ArgumentNullException
messageis null.
LogInfo(object, string, params object?[])
Writes an Info record for a sender that is not an ILoggerSource, under the name of its type.
public static void LogInfo(this object sender, string format, params object?[] args)
Parameters
senderobjectThe object that writes the record.
formatstringThe format string.
argsobject[]The format arguments.
Exceptions
- ArgumentNullException
formatis null.
LogInfo(ILoggerSource, string, object?)
Writes an Info record unless the effective level of the source is higher.
Added in ATAS 8.0.15.
public static void LogInfo(this ILoggerSource sender, string format, object? arg0)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
Exceptions
- ArgumentNullException
formatis null.
LogInfo(ILoggerSource, string, object?, object?)
Writes an Info record unless the effective level of the source is higher.
Added in ATAS 8.0.15.
public static void LogInfo(this ILoggerSource sender, string format, object? arg0, object? arg1)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
arg1objectThe second format argument.
Exceptions
- ArgumentNullException
formatis null.
LogInfo(ILoggerSource, string, object?, object?, object?)
Writes an Info record unless the effective level of the source is higher.
Added in ATAS 8.0.15.
public static void LogInfo(this ILoggerSource sender, string format, object? arg0, object? arg1, object? arg2)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
arg1objectThe second format argument.
arg2objectThe third format argument.
Exceptions
- ArgumentNullException
formatis null.
LogInfo(ILoggerSource, string, object, object, object, object)
Writes an Info record unless the effective level of the source is higher.
Added in ATAS 8.0.15.
public static void LogInfo(this ILoggerSource sender, string format, object arg0, object arg1, object arg2, object arg3)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
arg1objectThe second format argument.
arg2objectThe third format argument.
arg3objectThe fourth format argument.
Exceptions
- ArgumentNullException
formatis null.
LogInfo(ILoggerSource, string, params object?[])
Writes an Info record unless the effective level of the source is higher.
public static void LogInfo(this ILoggerSource sender, string format, params object?[] args)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
argsobject[]The format arguments.
Exceptions
- ArgumentNullException
formatis null.
LogWarn(object, string, params object?[])
Writes a Warning record for a sender that is not an ILoggerSource, under the name of its type.
public static void LogWarn(this object sender, string format, params object?[] args)
Parameters
senderobjectThe object that writes the record.
formatstringThe format string.
argsobject[]The format arguments.
Exceptions
- ArgumentNullException
formatis null.
LogWarn(ILoggerSource, string, bool)
Writes message as a Warning record without formatting it.
public static void LogWarn(this ILoggerSource sender, string message, bool isVisible = true)
Parameters
senderILoggerSourceThe source that writes the record.
messagestringThe text of the record.
isVisibleboolThe Utils.Common.Logging.LoggerItem.IsVisible value passed to the listeners; false keeps the record out of the platform's log panel while the log files still contain it.
Exceptions
- ArgumentNullException
messageis null.
LogWarn(ILoggerSource, string, object?)
Writes a Warning record unless the effective level of the source is higher.
Added in ATAS 8.0.15.
public static void LogWarn(this ILoggerSource sender, string format, object? arg0)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
Exceptions
- ArgumentNullException
formatis null.
LogWarn(ILoggerSource, string, object?, object?)
Writes a Warning record unless the effective level of the source is higher.
Added in ATAS 8.0.15.
public static void LogWarn(this ILoggerSource sender, string format, object? arg0, object? arg1)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
arg1objectThe second format argument.
Exceptions
- ArgumentNullException
formatis null.
LogWarn(ILoggerSource, string, object?, object?, object?)
Writes a Warning record unless the effective level of the source is higher.
Added in ATAS 8.0.15.
public static void LogWarn(this ILoggerSource sender, string format, object? arg0, object? arg1, object? arg2)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
arg0objectThe first format argument.
arg1objectThe second format argument.
arg2objectThe third format argument.
Exceptions
- ArgumentNullException
formatis null.
LogWarn(ILoggerSource, string, params object?[])
Writes a Warning record unless the effective level of the source is higher.
public static void LogWarn(this ILoggerSource sender, string format, params object?[] args)
Parameters
senderILoggerSourceThe source that writes the record.
formatstringThe format string.
argsobject[]The format arguments.
Exceptions
- ArgumentNullException
formatis null.
LogWarnWithFloodProtection(ILoggerSource, string, object?)
Logs not more than 1 time a second per tracker object This allows to reduce logs flooding with similar messages but still print them
public static void LogWarnWithFloodProtection(this ILoggerSource sender, string message, object? tracker = null)
Parameters
senderILoggerSourcemessagestringtrackerobject
Exceptions
- ArgumentNullException