CounterAttribute 类

定义

提供有关指导生产强类型 64 位整数计数器指标工厂方法和关联类型的信息。

public ref class CounterAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method)]
[System.Diagnostics.Conditional("CODE_GENERATION_ATTRIBUTES")]
public sealed class CounterAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method)>]
[<System.Diagnostics.Conditional("CODE_GENERATION_ATTRIBUTES")>]
type CounterAttribute = class
    inherit Attribute
Public NotInheritable Class CounterAttribute
Inherits Attribute
继承
CounterAttribute
属性

示例

static partial class Metric
{
    [Counter("RequestName", "RequestStatusCode")]
    static partial RequestCounter CreateRequestCounter(Meter meter);
}

注解

此属性应用于具有以下约束的方法:

  • 必须是分部方法。
  • 必须作为类型返回 metricName 。 将生成具有该名称的类。
  • 不能为泛型。
  • 必须具有 System.Diagnostics.Metrics.Meter 作为第一个参数。
  • 必须具有作为字符串类型参数提供 staticTagNames 的所有键。

构造函数

名称 说明
CounterAttribute(String[])

初始化 CounterAttribute 类的新实例。

CounterAttribute(Type)

初始化 CounterAttribute 类的新实例。

属性

名称 说明
Name

获取或设置指标的名称。

TagNames

获取指标的标记名称。

Type

获取提供指标标记值的类型。

Unit

获取或设置指标的度量单位。

适用于