C# Application Insights - TelemetryClient 的多个实例

bli*_*izz 0 c# logging azure telemetry azure-application-insights

我想将 Application Insights 遥测数据记录到我自己的帐户和客户的帐户中。

使用 TelemetryClient 的多个实例将相同的数据记录到两个不同的 Application Insights 检测密钥是否存在任何问题?或者有更好的方法来做到这一点吗?

Zak*_*iMa 5

您可以在 TelemetryClient 级别指定 InstrumentationKey:

    this.Client = new TelemetryClient();
    this.Client.InstrumentationKey = "<your ikey>";
Run Code Online (Sandbox Code Playgroud)

或者直接在单个项目级别:

    public void ModifyItem(ITelemetry item)
    {
        // Replace ikey
        item.Context.InstrumentationKey = this.ikey;
    }
Run Code Online (Sandbox Code Playgroud)

如果您要将自动收集的数据发送到不同的 ikey,那么您可以在 TelemetryInitializer 中修改仪器密钥,甚至可以使用 TelemetryProcessor 自己直接数据。

  • 是的,您可以将数据发送到不同的 AI 资源。 (2认同)