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文本的依赖。
在与@ dmitry-matveev交谈之后,它理论上是可能的,但是这个理论可能并不值得实际尝试。这需要很多的东西,你可能更适合使用自定义事件或自定义属性手动录制自己,除非你有一个非常庞大和复杂的控制台应用程序,你正在尝试。 –
谢谢。正如你所说,我会手动记录所需的信息。 – Chatumbabub