CompositeLogger

Aggregates all loggers from component references under a single component.

Inherits: IReferenceable, Logger

Description

The CompositeLogger class allows you to aggregate loggers from component references into a single component.

Important points

  • It allows to log messages and conveniently send them to multiple destinations.

References

  • *:logger:*:*:1.0 - (optional) ILogger components to pass log messages

Constructors

Creates a new instance of the logger.

public CompositeLogger(IReferences references = null)

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

Fields

_loggers

protected _loggers: List<ILogger> = new List<ILogger>()

Instance methods

SetReferences

Sets references to dependent components.

public override void SetReferences(IReferences references)

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

Write

Writes a log message to the logger destination.

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

  • 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.

Examples

class MyComponent: IConfigurable, IReferenceable 
{
    CompositeLogger _logger = new CompositeLogger();
    public void Configure(ConfigParams config)
    {
        this._logger.Configure(config);
        ...
    }
    public void SetReferences(IReferences references)
    {
        this._logger.SetReferences(references);
        ...
    }
    public void MyMethod(IContext context)
    {
        this._logger.Debug(context, "Called method mycomponent.mymethod");
        ...
    }
}

See also