2017-08-29 48 views
1

想象一下使用ADO.NET查询sql数据库的.NET 4.6控制台应用程序。它正在捕获Application Insights中.net 4.6应用程序中支持的SQL命令文本?

static void Main(string[] args) 
    { 
     TelemetryConfiguration.Active.InstrumentationKey = "my key"; 

     var tc = new TelemetryClient(TelemetryConfiguration.Active); 

     tc.TrackEvent("App start"); 

     string ConnString = "Data Source=localhost;Initial Catalog=MyDb;Persist Security Info=True;User ID=sa;Password=****;MultipleActiveResultSets=True"; 
     string SqlString = "Select * From Customers"; 
     using (SqlConnection conn = new SqlConnection(ConnString)) 
     { 
      using (SqlCommand cmd = new SqlCommand(SqlString, conn)) 
      { 
       cmd.CommandType = CommandType.Text; 

       conn.Open(); 
       using (SqlDataReader reader = cmd.ExecuteReader()) 
       { 
        var res = reader.Read(); 
       } 
      } 
     } 


     tc.TrackEvent("App stop"); 
     tc.Flush(); 
     Thread.Sleep(5000); 
    } 

它在这种情况下捕获SQL命令文本是否受支持?或仅支持IIS和Azure应用程序?

在此示例中,我希望在依赖项事件中的Application Insights上看到文本“Select * From Customers”,但此文本不存在。只有少数其他属性,如持续时间,客户端IP等,而不是sql文本的依赖。

回答

2

sql语句由“状态监视器”收集,该状态监视器在运行时作为.net分析器在Web应用程序上运行。

https://docs.microsoft.com/en-us/azure/application-insights/app-insights-asp-net-dependencies

我到处打听,但我相当肯定这是不容易钩住了对非Web应用程序,而无需通过箍的很多跳跃。

+0

在与@ dmitry-matveev交谈之后,它理论上是可能的,但是这个理论可能并不值得实际尝试。这需要很多的东西,你可能更适合使用自定义事件或自定义属性手动录制自己,除非你有一个非常庞大和复杂的控制台应用程序,你正在尝试。 –

+0

谢谢。正如你所说,我会手动记录所需的信息。 – Chatumbabub

相关问题