c# - 如何知道应用程序洞察遥测客户端是否正常运行?

标签 c# azure azure-application-insights

此代码执行时没有任何错误,但显然不会在 ApplicationInsights 中记录任何内容。 foobar 键无效。

 var client = new TelemetryClient
 {
    Context = { InstrumentationKey = "foobar" }
 };

 client.TrackEvent(telemetryEvent);

我明白这可能是一件好事。我不希望我的应用程序崩溃,因为 AppInsights 不可用。但如果以某种方式知道它无法访问,那就太好了,这样我就可以做其他事情了。

我认为可能附加的可能错误:

  • 无法访问 API
  • 事件格式错误
  • API key 无效
  • 等等

其中一些可能是暂时的(api 暂时不可用),但其他可能不是(无效的 api key )。

有什么方法可以“测试”客户端对这些情况的 react 吗?

类似于:

if (!client.IsAppInsightReachable)
{
  //Send an email to someone so he can check if everything is OK
}

最佳答案

如果你真的想这样做,你可能可以,但可能需要大量的重新发明轮子的工作。

你必须自己做很多工作,实现或包装类似 ITelemetryChannel 的东西。做你想做的事。

various application insights sdks are up on github 的大部分来源:

关于c# - 如何知道应用程序洞察遥测客户端是否正常运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30533809/

相关文章:

azure - ListQueuesSegmented 与 ListQueues

java - 使用 java 从 Azure 存储获取文档/word 文件内容。

使用服务主体的 Azure 分析服务连接不起作用

azure-application-insights - Application Insights .net core : Process was called on the TelemetrySink after it was disposed, 遥测数据被丢弃

c# - 为什么我所有的 log4net 级别都是错误的?

c# - 为什么 List<double> 显式转换为 IEnumerable<object> 会抛出异常?

c# - 带有本地 SQL Server CE DLL 的 Entity Framework 代码优先 "ADO.NET provider not found"

c# - TinyMapper : Does calling TinyMapper. 绑定(bind)<TTarget, TSource>();导致性能问题?应该只调用一次吗?

azure - 应用洞察 : SQL Dependency result code "-2"

Azure Log Analytics - 查询 Application Insight 自定义指标