Logger that caches captured log messages in memory and periodically dumps them.
Inherits: Logger
Description
The CachedLogger class allows you to create a logger that caches captured log messages in memory and periodically dumps them.
Important points
- Child classes implement saving cached messages to their specified destinations.
Configuration parameters
- level: maximum log level to capture
- source: source’s (context) name
- options:
- interval: interval in milliseconds to save log messages (default: 10 seconds).
- max_cache_size: maximum number of messages stored in this cache (default: 100).
References
- *:context-info:*:*:1.0 - (optional) ContextInfo to detect the context id and specify the counters' source
Fields
Instance methods
Clear
Clears (removes) all cached log messages.
void Clear()
Configure
Configures a component by passing its configuration parameters.
public override
void Configure(ConfigParams config)
- config: ConfigParams - configuration parameters to be set.
Dump
Dumps (writes) the currently cached log messages.
public
void Dump()
Update
Sets message cache as updated and dumps it when timeout expires.
protected
void Update()
Write
Writes a log message to the logger’s destination.
public 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.
Abstract methods
Save
Saves log messages from the cache.
protected abstract
Save(List<LogMessage> messages)
- messages: LogMessage - list with log messages