c# - 我在 Application Insights 中看不到我的轨迹跟踪消息

标签 c# azure azure-application-insights

我有一个简单的控制台应用程序来跟踪跟踪。但是,它不会在 Azure Web 门户的应用程序见解中记录跟踪消息。我错过了什么?

我查看了 https://learn.microsoft.com/en-us/azure/application-insights/application-insights-console来自 docs.ms.com,但在那里找不到答案。

class Program
{
    static void Main(string[] args)
    {
        TelemetryConfiguration.Active.InstrumentationKey = "<KEY_HERE>";
        var telemetryClient = new TelemetryClient();

        // Get the object used to communicate with the FTP server
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(Properties.Settings.Default.FtpEndpoint);

        // FTP credentials
        request.Credentials = new NetworkCredential(Properties.Settings.Default.FtpUserName, Properties.Settings.Default.FtpPassword);

        // FTP request method
        request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

        using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
        using (Stream responseStream = response.GetResponseStream())
        using (StreamReader reader = new StreamReader(responseStream))
        {
            telemetryClient.TrackTrace("Successfully retrieved a list of FTP directories");
            telemetryClient.Flush();

            Console.WriteLine(reader.ReadToEnd());
        }
    }
}

最佳答案

需要将TelemetryConfiguration对象放入TelemetryClient()中。 请确保已分配右键。

关于c# - 我在 Application Insights 中看不到我的轨迹跟踪消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48485084/

相关文章:

Azure Active Directory 组 - 通过 API 更改组策略

Azure Application Insights 在相同的时间戳处多次显示同一事件

c# - 使用 BlobTrigger 的 Azure 函数中的 Activity.Current 为 null

c# - null 和 datetime 之间没有隐式转换

azure - 使用 azure secret 提供者类进行 kustomize

c# - LINQ:不是任何 vs 全部都不是

c# - GetTable 不适用于 Azure SQL 表(Xamarin Forms)

azure - 如何根据自定义图表中的azure仪表板中的选定时间段计算时间粒度

c# - 如何在 JSON.NET 中实现自定义 JsonConverter?

c# - 哪个是 C# 中类型转换的最佳实践?