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
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, string correlationId, Exception error, string message)
- level: LogLevel - log level.
- correlationId: string - (optional) transaction id used to trace execution through the 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(String correlationId)
{
this._logger.Debug(correlationId, "Called method mycomponent.mymethod");
...
}
}