LoggingHelper
Extension class for ILogSource.
Métodos
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Retorna: The resulting value, or the default value of T if an error occurs.
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.
Retorna: The resulting value, or the default value of T if an error occurs.
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.
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.
Retorna: The resulting value, or the default value of T if an error occurs.
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.
Retorna: An enumerable of filtered messages.
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.
Retorna: The logging level.
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.
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.
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.
Retorna: A new task representing the continuation.
public static Task ObserveErrorAndLog(Task task)
result = LoggingHelper.ObserveErrorAndLog(task)
Observes errors from the task and logs them.
- task
- The task to observe.
Retorna: A new task representing the continuation.
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.
Retorna: A new task representing the continuation.
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.
Retorna: A new task representing the continuation.
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.
Campos
public static readonly Func<LogMessage, bool> OnlyError
value = LoggingHelper.OnlyError
The filter that only accepts messages of Error type.
public static readonly Func<LogMessage, bool> OnlyWarning
value = LoggingHelper.OnlyWarning
The filter that only accepts messages of Warning type.