Logger

Logger that captures and formats log messages.

Inherits: ILogger, IReconfigurable, IReferenceable

Description

The Logger class allows you to create a logger that captures and formats logs messages.

Important points

  • Child classes take the captured messages and write them to their specific destinations.

Configuration parameters

Parameters to pass to the configure method for component configuration:

  • level: maximum log level to capture
  • source: source (context) name

References

  • *:context-info:*:*:1.0 - (optional) ContextInfo to detect the context id and specify counters source

Fields

_level

Maximum log level to capture

protected _level: LogLevel = LogLevel.Info

_source

source (context) name

protected _source: string = null

Instance methods

ComposeError

Composes a human-readable error description

protected string ComposeError(Exception error)

  • error: Exception - error to format.
  • returns: string - human-redable error description.

Configure

Configures a component by passing its configuration parameters.

public virtual void Configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

Debug

Logs high-level debug information for troubleshooting.

public void Debug(IContext context, string message, params object[] args)

  • context: IContext - (optional) a context to trace execution through a call chainin.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

Debug

Logs high-level debug information for troubleshooting.

public void Debug(IContext context, Exception error, string message = null, params object[] args)

  • context: IContext - (optional) a context to trace execution through a call chainn.
  • error: Exception - error object associated with this message.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

Error

Logs recoverable application error.

public void Error(IContext context, string message, params object[] args)

  • context: IContext - (optional) a context to trace execution through a call chainn.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

Error

Logs recoverable application error.

public void Error(IContext context, Exception error, string message = null, params object[] args)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • error: Exception - error object associated with this message.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

Fatal

Logs fatal (unrecoverable) message that caused the process to crash.

public void Fatal(IContext context, string message, params object[] args)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

Fatal

Logs fatal (unrecoverable) message that caused the process to crash.

public void Fatal(IContext context, Exception error, string message = null, params object[] args)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • error: Exception - error object associated with this message.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

FormatAndWrite

Formats the log message and writes it to the logger destination.

protected void FormatAndWrite(LogLevel level, IContext context, Exception error, string message, object[] args)

  • level: LogLevel - log level.
  • context: IContext - (optional) a context to trace execution through a call chain.
  • error: Exception - error object associated with this message.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

Info

Logs an important information message

public void Info(IContext context, string message, params object[] args): void

  • context: IContext - (optional) a context to trace execution through a call chain.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

Info

Logs an important information message

public void Info(IContext context, Exception error, string message = null, params object[] args): void

  • context: IContext - (optional) a context to trace execution through a call chain.
  • error: Exception - error object associated with this message.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

Log

Logs a message at a specified log level.

public void Log(LogLevel level, IContext context, Exception error, string message, params object[] args)

  • level: LogLevel - log level.
  • context: IContext - (optional) a context to trace execution through a call chain.
  • error: Exception - error object associated with this message.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

SetReferences

Sets references to dependent components.

public override void SetReferences(IReferences references)

  • references: IReferences - references to locate the component dependencies.

Trace

Logs low-level debug information for troubleshooting.

public void Trace(IContext context, string message, params object[] args)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

Trace

Logs low-level debug information for troubleshooting.

public void Trace(IContext context, Exception error, string message = null, params object[] args)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • error: Exception - error object associated with this message.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

Warn

Logs a warning that may or may not have a negative impact.

public void Warn(IContext context, string message, params object[] args)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

Warn

Logs a warning that may or may not have a negative impact.

public void Warn(IContext context, Exception error, string message = null, params object[] args)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • error: Exception - error object associated with this message
  • message: string - human-readable message to log.
  • args: object[] - arguments to parameterize the message.

Abstract methods

Write

Writes a log message to the logger destination.

protected abstract void Write(LogLevel level, IContext context, Exception error, string message)

  • level: LogLevel - a log level.
  • context: IContext - (optional) a context to trace execution through a call chain.
  • error: Exception - an error object associated with this message.
  • message: string - a human-readable message to log.

See also