【发布时间】:2017-01-04 13:17:27
【问题描述】:
我正在尝试在类库项目中设置和使用application insights。我想在 Visual Studio 中调试时在离线模式下使用它。
遵循一些指南后,我有这个:
(在 Engine.cs 的构造函数中 - 我的库的“主”类)
_telemetryClient = new TelemetryClient();
// Set session data:
_telemetryClient.Context.User.Id = Environment.UserName;
_telemetryClient.Context.Session.Id = Guid.NewGuid().ToString();
_telemetryClient.Context.Device.OperatingSystem = Environment.OSVersion.ToString();
然后在类的main方法中:
var metrics = new Dictionary<string, double>();
var properties = new Dictionary<string, string>();
try
{
// Do stuff and track metrics code...
telemetryClient?.TrackEvent("Some Event", properties, metrics);
_telemetryClient?.Flush();
System.Threading.Thread.Sleep(1000);
}
catch (Exception exception)
{
_telemetryClient?.TrackException(exception, properties, metrics);
_telemetryClient?.Flush();
throw;
}
由于我希望在使用库的调用代码中配置日志记录(例如 Azure 密钥等),因此该项目没有其他配置,也没有 applicationinsights.config。
但是,当我在 VS 中进行调试时,在选择“选择 Application Insights 资源”-> 上次调试会话后,“Application Insights 搜索没有数据”。
【问题讨论】:
-
对不起,如果这听起来不对,但如果我错了,请纠正我。我认为创建应用程序洞察力是为了确定系统在负载下的运行情况(即有多少人同时访问系统的某些部分)。使用 Application Insights 会让您知道只有您在访问它。使用这个系统做一个仅限本地的图书馆时需要什么数据?也许改用内置的配置文件系统?
-
这是完全有效的 appinsights 用法。它还处理使用情况(自定义事件)、异常等。
标签: c# azure-application-insights