LoggingHelper

Ecng.Logging

Extension class for ILogSource.

Methoden

AddDebugLog
public static void AddDebugLog(ILogReceiver receiver, string message, object[] args)
LoggingHelper.AddDebugLog(receiver, message, args)

To record a debug message to the log.

receiver
Logs receiver.
message
Text message.
args
Text message settings. Used if the message is a format string.
AddErrorLog
public static void AddErrorLog(ILogReceiver receiver, Exception exception)
LoggingHelper.AddErrorLog(receiver, exception)

To record an error to the log.

receiver
Logs receiver.
exception
Error details.
AddErrorLog
public static void AddErrorLog(ILogReceiver receiver, string message, object[] args)
LoggingHelper.AddErrorLog(receiver, message, args)

To record an error to the log.

receiver
Logs receiver.
message
Text message.
args
Text message settings. Used if the message is a format string.
AddErrorLog
public static void AddErrorLog(ILogReceiver receiver, Func<string> getMessage)
LoggingHelper.AddErrorLog(receiver, getMessage)

To record an error to the log.

receiver
Logs receiver.
getMessage
The function returns the text for Message.
AddErrorLog
public static void AddErrorLog(ILogReceiver receiver, Exception exception, string format)
LoggingHelper.AddErrorLog(receiver, exception, format)

To record an error to the log.

receiver
Logs receiver.
exception
Error details.
format
A format string.
AddInfoLog
public static void AddInfoLog(ILogReceiver receiver, Func<string> getMessage)
LoggingHelper.AddInfoLog(receiver, getMessage)

To record a message to the log.

receiver
Logs receiver.
getMessage
The function returns the text for Message.
AddInfoLog
public static void AddInfoLog(ILogReceiver receiver, string message, object[] args)
LoggingHelper.AddInfoLog(receiver, message, args)

To record a message to the log.

receiver
Logs receiver.
message
Text message.
args
Text message settings. Used if the message is a format string.
AddLog
public static void AddLog(ILogReceiver receiver, LogLevels level, Func<string> getMessage)
LoggingHelper.AddLog(receiver, level, getMessage)

To record a message to the log.

receiver
Logs receiver.
level
The level of the log message.
getMessage
The function that returns the text for Message.
AddVerboseLog
public static void AddVerboseLog(ILogReceiver receiver, string message, object[] args)
LoggingHelper.AddVerboseLog(receiver, message, args)

To record a verbose message to the log.

receiver
Logs receiver.
message
Text message.
args
Text message settings. Used if the message is a format string.
AddWarningLog
public static void AddWarningLog(ILogReceiver receiver, string message, object[] args)
LoggingHelper.AddWarningLog(receiver, message, args)

To record a warning to the log.

receiver
Logs receiver.
message
Text message.
args
Text message settings. Used if the message is a format string.
AddWarningLog
public static void AddWarningLog(ILogReceiver receiver, Func<string> getMessage)
LoggingHelper.AddWarningLog(receiver, getMessage)

To record a warning to the log.

receiver
Logs receiver.
getMessage
The function returns the text for Message.
DoWithLog
public static void DoWithLog(Action action)
LoggingHelper.DoWithLog(action)

Wrap the specified action in a try/catch clause with logging.

action
The action to execute.
DoWithLogAsync
public static Task DoWithLogAsync(Func<CancellationToken, Task> action, CancellationToken cancellationToken)
result = LoggingHelper.DoWithLogAsync(action, cancellationToken)

Wrap the specified async action in a try/catch clause with logging.

action
The async action to execute.
cancellationToken
The cancellation token.
DoWithLogAsync
public static ValueTask DoWithLogAsync(Func<CancellationToken, ValueTask> action, CancellationToken cancellationToken)
result = LoggingHelper.DoWithLogAsync(action, cancellationToken)

Wrap the specified async action in a try/catch clause with logging.

action
The async action to execute.
cancellationToken
The cancellation token.
DoWithLogAsync``1
public static ValueTask<T> DoWithLogAsync<T>(Func<CancellationToken, ValueTask<T>> action, CancellationToken cancellationToken)
result = LoggingHelper.DoWithLogAsync(action, cancellationToken)

Wrap the specified async function in a try/catch clause with logging.

action
The async function to execute.
cancellationToken
The cancellation token.

Rückgabe: The resulting value, or the default value of T if an error occurs.

DoWithLogAsync``1
public static Task<T> DoWithLogAsync<T>(Func<CancellationToken, Task<T>> action, CancellationToken cancellationToken)
result = LoggingHelper.DoWithLogAsync(action, cancellationToken)

Wrap the specified async function in a try/catch clause with logging.

action
The async function to execute.
cancellationToken
The cancellation token.

Rückgabe: The resulting value, or the default value of T if an error occurs.

DoWithLog``1
public static void DoWithLog<T>(Func<IDictionary<T, Exception>> action)
LoggingHelper.DoWithLog(action)

Executes the function that returns a dictionary, logs any exceptions, and logs a specific error for each key/value pair.

action
The function to execute that returns a dictionary.
DoWithLog``1
public static T DoWithLog<T>(Func<T> action)
result = LoggingHelper.DoWithLog(action)

Wrap the specified function in a try/catch clause with logging.

action
The function to execute.

Rückgabe: The resulting value, or the default value of T if an error occurs.

Filter
public static IEnumerable<LogMessage> Filter(IEnumerable<LogMessage> messages, ICollection<Func<LogMessage, bool>> filters)
result = LoggingHelper.Filter(messages, filters)

Filters messages based on provided filters.

messages
The collection of messages to filter.
filters
A collection of filter predicates to determine which messages to include.

Rückgabe: An enumerable of filtered messages.

GetLogLevel
public static LogLevels GetLogLevel(ILogSource source)
result = LoggingHelper.GetLogLevel(source)

Get LogLevel for the source. If the value is equal to Inherit, then the parental source level is taken.

source
The log source.

Rückgabe: The logging level.

LogError
public static void LogError(Exception error, string format)
LoggingHelper.LogError(error, format)

To record an error to the ambient Application.

error
Error.
format
A format string.
LogError
public static void LogError(ILogReceiver receiver, Exception exception)
LoggingHelper.LogError(receiver, exception)

To record an error to the log.

receiver
Logs receiver.
exception
Error details.
ObserveError
public static Task ObserveError(Task task, Action<Exception> observer, Action<Task> other)
result = LoggingHelper.ObserveError(task, observer, other)

Continues the task, observing any errors and optionally executing the specified action.

task
The task to observe.
observer
An action to handle exceptions if the task faults.
other
An optional action to execute if the task completes successfully.

Rückgabe: A new task representing the continuation.

ObserveErrorAndLog
public static Task ObserveErrorAndLog(Task task)
result = LoggingHelper.ObserveErrorAndLog(task)

Observes errors from the task and logs them.

task
The task to observe.

Rückgabe: A new task representing the continuation.

ObserveErrorAndTrace
public static Task ObserveErrorAndTrace(Task task)
result = LoggingHelper.ObserveErrorAndTrace(task)

Observes errors from the task and traces them using Object).

task
The task to observe.

Rückgabe: A new task representing the continuation.

ObserveError``1
public static Task ObserveError<T>(Task<T> task, Action<Exception> observer, Action<Task<T>> other)
result = LoggingHelper.ObserveError(task, observer, other)

Continues the generic task, observing any errors and optionally executing the specified action.

task
The task to observe.
observer
An action to handle exceptions if the task faults.
other
An optional action to execute if the task completes successfully.

Rückgabe: A new task representing the continuation.

WriteMessage
public static void WriteMessage(ILogListener listener, LogMessage message)
LoggingHelper.WriteMessage(listener, message)

Writes a single log message using the specified listener.

listener
The log listener.
message
The log message to write.

Felder

OnlyError
public static readonly Func<LogMessage, bool> OnlyError
value = LoggingHelper.OnlyError

The filter that only accepts messages of Error type.

OnlyWarning
public static readonly Func<LogMessage, bool> OnlyWarning
value = LoggingHelper.OnlyWarning

The filter that only accepts messages of Warning type.