Class ActivityMonitor
Concrete implementation of IActivityMonitor.
Inherited Members
Namespace: CK.Core
Assembly: CK.ActivityMonitor.dll
Syntax
public class ActivityMonitor : IActivityMonitorImpl, IActivityMonitor, IUniqueId
Constructors
| Improve this Doc View SourceActivityMonitor()
Initializes a new ActivityMonitor that applies all AutoConfiguration and has no Topic initially set.
Declaration
public ActivityMonitor()
ActivityMonitor(ActivityMonitorOutput, CKTrait, Boolean)
Initializes a new ActivityMonitor with a specific Output or null to postpone the setting of Output by using SetOutput(ActivityMonitorOutput).
Declaration
protected ActivityMonitor(ActivityMonitorOutput output, CKTrait tags = null, bool applyAutoConfigurations = true)
Parameters
| Type | Name | Description |
|---|---|---|
| ActivityMonitorOutput | output | The output to use. Can be null. |
| CK.Core.CKTrait | tags | Initial tags. |
| Boolean | applyAutoConfigurations | Whether AutoConfiguration should be applied. |
ActivityMonitor(Boolean, String)
Initializes a new ActivityMonitor that optionally applies AutoConfiguration and with an initial topic.
Declaration
public ActivityMonitor(bool applyAutoConfigurations, string topic = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | applyAutoConfigurations | Whether AutoConfiguration should be applied. |
| String | topic | Optional initial topic (can be null). |
ActivityMonitor(String)
Initializes a new ActivityMonitor that applies all AutoConfiguration and has an initial Topic set.
Declaration
public ActivityMonitor(string topic)
Parameters
| Type | Name | Description |
|---|---|---|
| String | topic | Initial topic (can be null). |
Fields
| Improve this Doc View SourceAutoConfiguration
The automatic configuration actions. Registers actions via += (or Combine(Delegate, Delegate) if you like pain), unregister with -= operator (or Remove(Delegate, Delegate)). Simply sets it to null to clear all currently registered actions (this, of course, only from tests and not in real code).
Declaration
public static Action<IActivityMonitor> AutoConfiguration
Field Value
| Type | Description |
|---|---|
| Action<IActivityMonitor> |
CriticalErrorCollector
The monitoring error collector. Any error that occurs while dispatching logs to IActivityMonitorClient are collected and the culprit is removed from Output. See CriticalErrorCollector.
Declaration
public static readonly CriticalErrorCollector CriticalErrorCollector
Field Value
| Type | Description |
|---|---|
| CK.Core.CriticalErrorCollector |
NoLogText
The no-log text replaces any null or empty log text.
Declaration
public static readonly string NoLogText
Field Value
| Type | Description |
|---|---|
| String |
ParkLevel
Declaration
public static readonly string ParkLevel
Field Value
| Type | Description |
|---|---|
| String |
SetTopicPrefix
Prefix used by SetTopic(String, String, Int32) is "Topic: ".
Declaration
public static readonly string SetTopicPrefix
Field Value
| Type | Description |
|---|---|
| String |
Properties
| Improve this Doc View SourceActualFilter
Gets the actual filter level for logs: this combines the configured MinimalFilter and the minimal requirements of any IActivityMonitorBoundClient that specifies such a minimal filter level.
Declaration
public LogFilter ActualFilter { get; }
Property Value
| Type | Description |
|---|---|
| LogFilter |
Implements
Remarks
This does NOT take into account the static (application-domain) DefaultFilter. This global default must be used if this ActualFilter is Undefined for Line or Group: the ShouldLogLine(IActivityMonitor, LogLevel, String, Int32) extension method takes it into account.
AutoTags
Gets or sets the tags of this monitor: any subsequent logs will be tagged by these tags. The CK.Core.CKTrait must be registered in ActivityMonitor.Tags. Modifications to this property are scoped to the current Group since when a Group is closed, this property (like MinimalFilter) is automatically restored to its original value (captured when the Group was opened).
Declaration
public CKTrait AutoTags { get; set; }
Property Value
| Type | Description |
|---|---|
| CK.Core.CKTrait |
Implements
| Improve this Doc View SourceCurrentGroup
Gets the currently opened group. Null when no group is currently opened.
Declaration
protected IActivityLogGroup CurrentGroup { get; }
Property Value
| Type | Description |
|---|---|
| IActivityLogGroup |
DefaultFilter
Gets or sets the default filter that should be used when the ActualFilter is Undefined. This configuration is per application domain (the backing field is static). It defaults to Trace.
Declaration
public static LogFilter DefaultFilter { get; set; }
Property Value
| Type | Description |
|---|---|
| LogFilter |
LastLogTime
Gets the last CK.Core.DateTimeStamp for this monitor.
Declaration
public DateTimeStamp LastLogTime { get; }
Property Value
| Type | Description |
|---|---|
| CK.Core.DateTimeStamp |
Implements
| Improve this Doc View SourceMinimalFilter
Gets or sets a filter based for the log level. Modifications to this property are scoped to the current Group since when a Group is closed, this property (like AutoTags) is automatically restored to its original value (captured when the Group was opened).
Declaration
public LogFilter MinimalFilter { get; set; }
Property Value
| Type | Description |
|---|---|
| LogFilter |
Implements
| Improve this Doc View SourceOutput
Gets the IActivityMonitorOutput for this monitor.
Declaration
public IActivityMonitorOutput Output { get; }
Property Value
| Type | Description |
|---|---|
| IActivityMonitorOutput |
Implements
| Improve this Doc View SourceTopic
Gets the current topic for this monitor. This can be any non null string (null topic is mapped to the empty string) that describes the current activity. It must be set with SetTopic(String, String, Int32) and unlike MinimalFilter and AutoTags, the topic is not reseted when groups are closed.
Declaration
public string Topic { get; }
Property Value
| Type | Description |
|---|---|
| String |
Implements
| Improve this Doc View SourceUniqueId
Gets the unique identifier for this monitor. It is a NewGuid() by default but specialized implementations can set it via the protected SetUniqueId(Guid) if a unique identifier exists in the context that can more easily identify this activity.
Declaration
protected Guid UniqueId { get; }
Property Value
| Type | Description |
|---|---|
| Guid |
Methods
| Improve this Doc View SourceCloseGroup(DateTimeStamp, Object)
Closes the current ActivityMonitor.Group. Optional parameter is polymorphic. It can be a string, a ActivityLogGroupConclusion, a List<T> or an IEnumerable<T> of ActivityLogGroupConclusion, or any object with an overridden ToString() method. See remarks (especially for List<ActivityLogGroupConclusion>).
Declaration
public virtual bool CloseGroup(DateTimeStamp logTime, object userConclusion = null)
Parameters
| Type | Name | Description |
|---|---|---|
| CK.Core.DateTimeStamp | logTime | Times-tamp of the group closing. |
| Object | userConclusion | Optional string, enumerable of ActivityLogGroupConclusion) or object to conclude the group. See remarks. |
Returns
| Type | Description |
|---|---|
| Boolean |
Implements
Remarks
An untyped object is used here to easily and efficiently accommodate both string and already existing ActivityLogGroupConclusion. When a List<ActivityLogGroupConclusion> is used, it will be directly used to collect conclusion objects (new conclusions will be added to it). This is an optimization.
ReentrancyAndConcurrencyLock()
Gets a disposable object that checks for reentrant and concurrent calls.
Declaration
protected IDisposable ReentrancyAndConcurrencyLock()
Returns
| Type | Description |
|---|---|
| IDisposable | A disposable object (that must be disposed). |
SetOutput(ActivityMonitorOutput)
Sets the Output.
Declaration
protected void SetOutput(ActivityMonitorOutput output)
Parameters
| Type | Name | Description |
|---|---|---|
| ActivityMonitorOutput | output | Can not be null. |
SetTopic(String, String, Int32)
Sets the current topic for this monitor. This can be any non null string (null topic is mapped to the empty string) that describes the current activity.
Declaration
public void SetTopic(string newTopic, string fileName = null, int lineNumber = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| String | newTopic | |
| String | fileName | |
| Int32 | lineNumber |
Implements
| Improve this Doc View SourceSetUniqueId(Guid)
Sets the unique identifier of this activity monitor. This must be used only during monitor construction or initialization, before the monitor is actually used.
Declaration
protected void SetUniqueId(Guid uniqueId)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | uniqueId | New unique identifier. |
UnfilteredLog(ActivityMonitorLogData)
Logs a text regardless of MinimalFilter level (except for Off). Each call to log is considered as a unit of text: depending on the rendering engine, a line or a paragraph separator (or any appropriate separator) should be appended between each text if the level is the same as the previous one. See remarks.
Declaration
public void UnfilteredLog(ActivityMonitorLogData data)
Parameters
| Type | Name | Description |
|---|---|---|
| ActivityMonitorLogData | data | Data that describes the log. When null or when MaskedLevel is None, nothing happens (whereas for group, a rejected group is recorded and returned). |
Implements
Remarks
A null or empty Text is logged as NoLogText. If needed, the special text ParkLevel ("PARK-LEVEL") breaks the current LogLevel and resets it: the next log, even with the same LogLevel, will be treated as if a different LogLevel is used.
UnfilteredOpenGroup(ActivityMonitorGroupData)
Opens a group regardless of ActualFilter level (except for Off). CloseGroup(DateTimeStamp, Object) must be called in order to close the group, and/or the returned object must be disposed (both can be called safely: the group is closed on the first action, any other attempt to close it again is ignored).
Declaration
public virtual IDisposableGroup UnfilteredOpenGroup(ActivityMonitorGroupData data)
Parameters
| Type | Name | Description |
|---|---|---|
| ActivityMonitorGroupData | data | Data that describes the log. When null or when MaskedLevel is None a rejected group is recorded and returned and must be closed. |
Returns
| Type | Description |
|---|---|
| IDisposableGroup | A disposable object that can be used to set a function that provides a conclusion text and/or close the group. |
Implements
Remarks
Opening a group does not change the current MinimalFilter, except when opening a Fatal or Error group: in such case, the MinimalFilter is automatically sets to Debug to capture all potential information inside the error group.
Changes to the monitor's current Filter or AutoTags that occur inside a group are automatically restored to their original values when the group is closed. This behavior guaranties that a local modification (deep inside unknown called code) does not impact caller code: groups are a way to easily isolate such configuration changes.
Note that this automatic configuration restoration works even if the group has been filtered and rejected.
Explicit Interface Implementations
| Improve this Doc View SourceIActivityMonitorImpl.CurrentGroup
Declaration
IActivityLogGroup IActivityMonitorImpl.CurrentGroup { get; }
Returns
| Type | Description |
|---|---|
| IActivityLogGroup |
Implements
| Improve this Doc View SourceIActivityMonitorImpl.InitializeTopicAndAutoTags(String, CKTrait, String, Int32)
Called by IActivityMonitorBoundClient clients to initialize Topic and AutoTag from inside their SetMonitor or any other methods provided that a reentrant and concurrent lock has been obtained (otherwise an InvalidOperationException is thrown).
Declaration
void IActivityMonitorImpl.InitializeTopicAndAutoTags(string newTopic, CKTrait newTags, string fileName, int lineNumber)
Parameters
| Type | Name | Description |
|---|---|---|
| String | newTopic | |
| CK.Core.CKTrait | newTags | |
| String | fileName | |
| Int32 | lineNumber |
Implements
| Improve this Doc View SourceIActivityMonitorImpl.OnClientMinimalFilterChanged(LogFilter, LogFilter)
Declaration
void IActivityMonitorImpl.OnClientMinimalFilterChanged(LogFilter oldLevel, LogFilter newLevel)
Parameters
| Type | Name | Description |
|---|---|---|
| LogFilter | oldLevel | |
| LogFilter | newLevel |
Implements
| Improve this Doc View SourceIActivityMonitorImpl.ReentrancyAndConcurrencyLock()
Declaration
IDisposable IActivityMonitorImpl.ReentrancyAndConcurrencyLock()
Returns
| Type | Description |
|---|---|
| IDisposable |
Implements
| Improve this Doc View SourceIActivityMonitorImpl.SignalChange()
Declaration
void IActivityMonitorImpl.SignalChange()
Implements
| Improve this Doc View SourceIUniqueId.UniqueId
Declaration
Guid IUniqueId.UniqueId { get; }
Returns
| Type | Description |
|---|---|
| Guid |