2017-09-04 2 views
0

서버 예외에서 트리거되도록 Application Insights 경고를 구성했습니다. 로직 앱을 통해 알림을 처리하고 있습니다. 정상적으로 작동합니다.Application Insights에서 예외 정보 얻기 Webhook JSON

alert 페이로드 JSON을 편집하여 예외 정보가 포함되도록하고 싶습니다. 알림 설정에 사용할 수있는 documentation에서 은, 우리가 이것에 대해 많이 언급하지 않는 푸른 모니터 API를

푸른 모니터 API Alert Rules Documentation를 사용하여 설정할 수 있습니다 일부 사용자 데이터를 포함하는 속성을 편집 할 수 있습니다 것으로 보인다.

제안 사항을 알려주십시오.

+0

예외의 세부 정보 오류 메시지를 받고이 메시지를 AI로 보내시겠습니까? 내가 아는 한, 출력은 오류 메시지를 얻을 것이다, 당신은 하늘 함수에서 논리 애플 리케이션 호출 하늘색 함수를 사용할 수있는 이러한 오류 메시지를 인공 지능에 보냅니다. 로직 애플 리케이션에서 하늘빛 함수를 호출하는 방법에 대해서는이 기사를 참조하십시오 (https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-scenario-function-sb- 방아쇠). –

+0

@BrandoZhang, 네, 저는 이것을 로직 앱을 통해 작동시킬 수있었습니다. 감사. – ak92

답변

0

Application Insights로 전송되는 예외 정보가 필요한 경우이 클래스를 사용해보십시오.

public static class StaticLogger 
{ 
    private static Object theThreadLock = new Object(); 

    private static TelemetryClient _APM; 
    public static TelemetryClient APM 
    { 
     get 
     { 
      lock (theThreadLock) 
      { 
       if (_APM == null) { _APM = new TelemetryClient(); } 
       return _APM; 
      } 
     } 
    } 

    public static void Warning(string message) 
    {    
     APM.TrackTrace(message, SeverityLevel.Warning); 
    }     

    public static void Error(Exception exception,LoggerEvents logEvent) 
    { 
     lock (theThreadLock) 
     { 
      var telemetry = new ExceptionTelemetry(exception); 
      APM.TrackEvent(logEvent.ToString()); 

      APM.TrackException(telemetry); 
     } 
    } 

    public static void Error(Exception exception,LoggerEvents logEvent, string fmt, params object[] vars) 
    { 
     lock (theThreadLock) 
     { 
      var telemetry = new ExceptionTelemetry(exception); 
      telemetry.Properties.Add("message", string.Format(fmt, vars)); 

      APM.TrackException(telemetry); 
     } 
    } 

    public static void Trace(string Message, string userID) 
    { 
     lock(theThreadLock) 
     { 
      APM.Context.User.Id = userID.ToString(); 
      Trace(Message); 
     } 

    } 
    public static void Trace(string Message) 
    { 
     lock (theThreadLock) 
     { 
      APM.TrackTrace(Message); 
     } 
    } 

    public static void TraceAPI(string currentNameSpace,string componentName, string method, string httpAction, TimeSpan timespan) 
    { 
     TraceAPI(currentNameSpace,componentName, method, httpAction, timespan, string.Empty); 
    } 

    public static void TraceAPI(string currentNameSpace,string componentName, string method, string httpAction, TimeSpan timespan, string fmt, params object[] vars) 
    { 
     TraceAPI(currentNameSpace,componentName, method, httpAction, timespan, string.Format(fmt, vars)); 
    } 

    public static void TraceAPI(string currentNameSpace,string componentName, string method, string httpAction, TimeSpan timespan, string properties) 
    { 
     lock (theThreadLock) 
     { 
      var telemetry = new TraceTelemetry("Trace API call", SeverityLevel.Information); 
      telemetry.Properties.Add("namespace", currentNameSpace); 
      telemetry.Properties.Add("component", componentName); 
      telemetry.Properties.Add("method", method); 
      telemetry.Properties.Add("HttpAction", httpAction); 
      telemetry.Properties.Add("timespan", timespan.ToString()); 

      if (!string.IsNullOrWhiteSpace(properties)) 
       telemetry.Properties.Add("properties", properties); 

      APM.TrackTrace(telemetry); 
     } 
    } 

    public static void TraceAPI(string currentNameSpace, string componentName, string method, string httpAction, TimeSpan timespan, IDictionary<string, string> properties = null) 
    { 
     lock (theThreadLock) 
     { 
      var telemetry = new TraceTelemetry("Trace API call", SeverityLevel.Information); 
      telemetry.Properties.Add("namespace", currentNameSpace); 
      telemetry.Properties.Add("component", componentName); 
      telemetry.Properties.Add("method", method); 
      telemetry.Properties.Add("HttpAction", httpAction); 
      telemetry.Properties.Add("timespan", timespan.ToString()); 

      if (properties != null) 
      { 
       foreach (var property in properties) 
       { 
        telemetry.Properties.Add(property.Key, property.Value); 
       } 
      } 

      APM.TrackTrace(telemetry); 
     } 
    } 

    public static void TraceMethod(string currentNameSpace, string componentName, string method, TimeSpan timespan, string properties) 
    { 
     lock (theThreadLock) 
     { 
      var telemetry = new TraceTelemetry("Trace API call", SeverityLevel.Information); 
      telemetry.Properties.Add("namespace", currentNameSpace); 
      telemetry.Properties.Add("component", componentName); 
      telemetry.Properties.Add("method", method);     
      telemetry.Properties.Add("timespan", timespan.ToString()); 

      if (!string.IsNullOrWhiteSpace(properties)) 
       telemetry.Properties.Add("properties", properties); 

      APM.TrackTrace(telemetry); 
     } 
    } 

    public static void TraceMethod(string currentNameSpace, string componentName, string method, TimeSpan timespan, IDictionary<string, string> properties = null) 
    { 
     lock (theThreadLock) 
     { 
      var telemetry = new TraceTelemetry("Trace API call", SeverityLevel.Information); 
      telemetry.Properties.Add("namespace", currentNameSpace); 
      telemetry.Properties.Add("component", componentName); 
      telemetry.Properties.Add("method", method); 
      telemetry.Properties.Add("timespan", timespan.ToString()); 

      if (properties != null) 
      { 
       foreach (var property in properties) 
       { 
        telemetry.Properties.Add(property.Key, property.Value); 
       } 
      } 

      APM.TrackTrace(telemetry); 
     } 
    } 
    public static void TrackEvent(string message) 
    { 
     lock (theThreadLock) 
     { 
      APM.TrackEvent(message); 
     } 
    } 

    public static void TrackEvent(string message, IDictionary<string, string> properties) 
    { 
     lock (theThreadLock) 
     { 
      var telemetry = new TraceTelemetry("Track Event", SeverityLevel.Information); 
      telemetry.Message = message; 

      if (properties != null) 
      { 
       foreach (var property in properties) 
       { 
        telemetry.Properties.Add(property.Key, property.Value); 
       } 
      } 

      APM.TrackEvent(message); 
     } 
    } 
} 

public sealed class LoggerEvents 
{ 
    private readonly string name; 
    private readonly int value; 

    public readonly static LoggerEvents ErrorWebSite = new LoggerEvents(1, "Error:WebSite"); 
    public readonly static LoggerEvents UnhandledException = new LoggerEvents(2, "UnhandledException"); 
    public readonly static LoggerEvents UserNotActive = new LoggerEvents(3, "UserNotActive"); 
    public readonly static LoggerEvents InvalidURL = new LoggerEvents(4, "InvalidURL"); 
    public readonly static LoggerEvents ConsentRefused = new LoggerEvents(5,"ConsentRefused"); 
    public readonly static LoggerEvents ConsentAccepted = new LoggerEvents(6, "ConsentAccepted"); 
    public readonly static LoggerEvents UserLoginSuccess = new LoggerEvents(7, "LoginSuccess"); 
    public readonly static LoggerEvents UserLoginFailure = new LoggerEvents(7, "LoginFailure"); 
    private LoggerEvents(int value, string name) 
    { 
     this.name = name; 
     this.value = value; 
    } 

    public override string ToString() 
    { 
     return name; 
    } 
} 
+0

궁금한 점이 ApplicationInsights에 예외 정보를 보내지 않습니다. 벌써 했어. – ak92

+0

샘플 클래스에는 추가 데이터, 속성 및 Exception Telemetry 사용 방법에 대한 예제가 있습니다. – aaronR

0

Logic App에서 Analytics 쿼리를 사용하여 예외 세부 사항을 얻을 수있었습니다. 지난 5 분 동안 모든 예외를 가져온 쿼리를 실행했습니다. 다음 HTTP 처리를 사용하여 추가 처리를 위해 API에 전달했습니다.

관련 문제