/// <summary> /// Initializes a new instance of the <see cref="AiException"/> class. /// </summary> /// <param name="exception">The exception being logged.</param> /// <param name="severity">The severity level <see cref="AiExceptionSeverity"/>.</param> public AiException(Exception exception, AiExceptionSeverity severity) { TypeName = exception.GetType().Name.Length > 1024 ? exception.GetType().Name.Substring(0, 1023) : exception.GetType().Name; Message = exception.Message; HasFullStack = !string.IsNullOrEmpty(exception.StackTrace); Stack = HasFullStack ? exception.StackTrace : null; ParsedStacks = ExceptionHelper.GetParsedStacked(exception); SeverityLevel = severity; }
public void WriteException(Exception exception, AiExceptionSeverity severity, Action <string> resultHandler = null) { if (!_aiConfig.LogExceptions) { return; } var logRequest = GetLogRequest("Exception"); logRequest.Data.BaseData.Exceptions = new List <AiException> { ExceptionHelper.GetAiException(exception) }; logRequest.Data.BaseData.SeverityLevel = severity.ToString(); var json = Serialization.SerializeRequest <AiLogRequest>(logRequest); SendToAi(json, resultHandler); }
/// <summary> /// Writes exception data to Application Insights. /// </summary> /// <param name="exception">The exception being logged.</param> /// <param name="aiExceptionSeverity">The severity level <see cref="AiExceptionSeverity"/>.</param> /// <param name="timestamp">The UTC timestamp of the event (default = DateTime.UtcNow).</param> /// <returns><c>true</c> if successfully logged, <c>false</c> otherwise.</returns> public bool WriteException(Exception exception, AiExceptionSeverity aiExceptionSeverity, DateTime?timestamp = null) { if (!Log("Exception", _disableExceptionTracking, _percentLoggedException)) { return(true); } timestamp = timestamp ?? DateTime.UtcNow; AiException aiException = new AiException(exception, aiExceptionSeverity); string json = GetExceptionJsonString(timestamp.Value, aiException); if (_enableDebug) { _tracingService.Trace($"DEBUG: Application Insights JSON: {CreateJsonDataLog(json)}"); } return(SendToAi(json)); }