简体   繁体   English

可以从控制台应用程序中使用VSO Application Insights吗?

[英]Can VSO Application Insights be used from a console application?

All the information that I can find on Application Insights seems to be targeted at websites / windows store / phone apps. 我可以在Application Insights上找到的所有信息似乎都针对网站/ Windows商店/手机应用。 I would like to monitor an Azure webjob, with the first step being able to monitor a command line app. 我想监视Azure webjob,第一步是能够监视命令行应用程序。 What do I need to do in order to make this work? 为了使这项工作,我需要做什么?

To use Application Insights in a Console application, 要在控制台应用程序中使用Application Insights,

  • Create a new Application Insights resource as described here . 按照此处所述创建新的Application Insights资源。

  • Use the NuGet package manager reference the Microsoft.ApplicationInsights package in your console application. 使用NuGet包管理器引用控制台应用程序中的Microsoft.ApplicationInsights包。

  • In the beginning of Program.Main , configure Application Insights to use the instrumentation key of your resource. Program.Main的开头,配置Application Insights以使用资源的检测密钥。

TelemetryConfiguration.Active.InstrumentationKey = "your key";

  • Create instance of TelemetryClient in the application code and call relevant Track methods as described here . 创建实例TelemetryClient在应用程序代码,并调用相关的Track为所描述的方法在这里

Yes.You could be used Application Insights from a console application. 是的。您可以从控制台应用程序中使用Application Insights。

Technically there is no problem. 从技术上讲,没有问题。 But after setting everything up you find that no or partial data goes to Application Insights, not the entire data. 但是在设置好所有内容之后,您会发现没有或部分数据会转到Application Insights,而不是整个数据。

For this situation, you need to add thread.sleep at the end of the code. 对于这种情况,您需要在代码末尾添加thread.sleep。

 public static void Main(string[] args)
    {

        //do your stuff
        System.Threading.Thread.Sleep(70000);
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM