代码之家  ›  专栏  ›  技术社区  ›  Emixam23

应用洞察遥测日志在Azure门户中的位置

  •  0
  • Emixam23  · 技术社区  · 5 年前

    我有这门课:

    public class TelemetryHelper : ITelemetryHelper
    {
        private TelemetryClient TelemetryClient { get; set; }
    
        public TelemetryHelper()
        {
            TelemetryConfiguration configuration = TelemetryConfiguration.CreateDefault();
            configuration.InstrumentationKey = ConfigurationManager.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"];
            TelemetryClient = new TelemetryClient(configuration);
        }
    
        #region Input
    
        public Task InfoAsync(DebugMessageType tag = DebugMessageType.Other, string message = null, Exception ex = null, [CallerMemberName] string callerFunction = "", [CallerLineNumber] int lineNumber = 0)
            => OutputInApplicationInsightsAsync(SeverityLevel.Information, tag, message, ex, callerFunction);
    
        public Task ErrorAsync(DebugMessageType tag = DebugMessageType.Other, string message = null, Exception ex = null, [CallerMemberName] string callerFunction = "", [CallerLineNumber] int lineNumber = 0)
            => OutputInApplicationInsightsAsync(SeverityLevel.Error, tag, message, ex, callerFunction);
    
        public Task WarnAsync(DebugMessageType tag = DebugMessageType.Other, string message = null, Exception ex = null, [CallerMemberName] string callerFunction = "", [CallerLineNumber] int lineNumber = 0)
            => OutputInApplicationInsightsAsync(SeverityLevel.Warning, tag, message, ex, callerFunction);
    
        #endregion Input
    
        private Task OutputInApplicationInsightsAsync(SeverityLevel level, DebugMessageType tag = DebugMessageType.Other, string message = null, Exception ex = null, string callerFunction = "")
        {
            var properties = new Dictionary<string, string> { { "Tag", tag.ToString() } };
    
            if (!string.IsNullOrWhiteSpace(callerFunction))
                properties.Add("CallerFunction", callerFunction);
    
            if (ex != null)
                properties.Add("Exception", ex.ToString());
    
            TelemetryClient.TrackTrace(message, level, properties);
            return Task.CompletedTask;
        }
    }
    

    我可以这样使用它:

    await TelemetryHelper.ErrorAsync(DebugMessageType.Service, ex.Message, ex, nameof(this.RunRemoveTasksAsync));
    

    不过,有人能告诉我这些日志在Azure门户中的位置吗。。我找了好几个小时都没找到

    0 回复  |  直到 5 年前
        1
  •  1
  •   Ivan Glasenberg    5 年前

    如果application insights链接正确并且遥测数据发送成功,则可以通过application insights中的这些位置找到它。

    第一个导航到azure门户->您在代码中链接的应用程序洞察。

    位置1:

    在“应用程序洞察”->“搜索”->中,您可以选择适当的“时间范围”和“事件类型”->然后单击“刷新”按钮。您可以看到日志:

    enter image description here

    在“应用程序洞察”->日志中。你可以写适当的 Kusto query TelemetryClient.TrackTrace 方法,所以您的日志应该在 踪迹

    enter image description here