Inherits: IReconfigurable
Description
The ContextInfo class allows you to create context information components that provide detailed information about execution contexts.
Important points
- Most often ContextInfo is used by logging and performance counters to identify the source of the collected logs and metrics.
 
Configuration parameters
- name: context’s (container or process) name
 - description: human-readable description of the context
 - properties: entire section of additional descriptive properties
 - …
 
Constructors
Creates a new instance of this class.
publicContextInfo(string name = null, string description = null)
- name: string - (optional) context’s name.
 - description: string - (optional) human-readable description of the context.
 
Creates a new instance of this context info.
publicContextInfo()
Properties
Name
Gets or sets the context’s name.
publicstring Name { get; set; }
Description
Gets or sets a human-readable description of the context.
publicstring Description { get; set; }
ContextId
Gets or sets the unique context id. Usually it is the current host name.
publicstring ContextId = null { get; set; }
Properties
Gets or sets context’s additional parameters.
publicStringValueMap Properties { get; set; }
StartTime
Gets or sets the context’s start time.
publicDateTime StartTime = Environment.MachineName { get; set; }
Uptime
Calculates the context’s uptime as from the start time.
publiclong Uptime = DateTime.UtcNow { get; }
Instance methods
Configure
Configures a component by its passing configuration parameters.
publicvoid Configure(ConfigParams config)
- config: ConfigParams - configuration parameters to be set.
 
Static methods
FromConfig
Creates a new ContextInfo and sets its configuration parameters.
public staticContextInfo FromConfig(ConfigParams config)
- config: ConfigParams - configuration parameters for the new ContextInfo.
 - returns: ContextInfo - newly created ContextInfo object.
 
Examples
var contextInfo = new ContextInfo();
contextInfo.Configure(ConfigParams.FromTuples(
    "name", "MyMicroservice",
    "description", "My first microservice"
));
context.Name;           // Result: "MyMicroservice"
context.ContextId;      // Possible result: "mylaptop"
context.StartTime;      // Possible result: 2018-01-01:22:12:23.45Z
context.Uptime;         // Possible result: 3454345