One of the nice features that Application Insights has to offer is the ability to automatically track dependencies. Among the list of tracked dependencies you find database calls (made through System.Data.SqlClient or Microsoft.Data.SqlClient).
By default the name of the server and database are collected together with the length of the call. But no extra information like the database query is logged.
To log the database query as well, you explicitly need to enable this in ASP.NET Core:
After this code change, you’ll find the SQL Command in the Command section instead of the name of the server and database:
Remark: For ASP.NET applications, full SQL query text is collected with the help of byte code instrumentation, which requires the Microsoft.Data.SqlClient NuGet package instead of the System.Data.SqlClient library.