private static Notification CreateNotification( Uri uri, string notificationId, string ruleId, FailureLevel level, Exception exception, bool persistExceptionStack, params string[] args) { string messageFormat = GetMessageFormatResourceForNotification(notificationId); string message = string.Format(CultureInfo.CurrentCulture, messageFormat, args); string exceptionMessage = exception?.Message; if (!string.IsNullOrEmpty(exceptionMessage)) { // {0} ('{1}') message = string.Format(CultureInfo.InvariantCulture, SdkResources.NotificationWithExceptionMessage, message, exceptionMessage); } var exceptionData = exception != null && persistExceptionStack ? ExceptionData.Create(exception) : null; var physicalLocation = uri != null ? new PhysicalLocation { ArtifactLocation = new ArtifactLocation { Uri = uri }, } : null; var notification = new Notification { PhysicalLocation = physicalLocation, Id = notificationId, RuleId = ruleId, Level = level, Message = new Message { Text = message }, Exception = exceptionData }; return(notification); }
public static Notification CreateNotification( Uri uri, string notificationId, string ruleId, FailureLevel level, Exception exception, bool persistExceptionStack, string messageFormat, params string[] args) { messageFormat = messageFormat ?? GetMessageFormatResourceForNotification(notificationId); string message = string.Format(CultureInfo.CurrentCulture, messageFormat, args); string exceptionMessage = exception?.Message; if (!string.IsNullOrEmpty(exceptionMessage)) { // {0} ('{1}') message = string.Format(CultureInfo.InvariantCulture, SdkResources.NotificationWithExceptionMessage, message, exceptionMessage); } var exceptionData = exception != null && persistExceptionStack ? ExceptionData.Create(exception) : null; var physicalLocation = uri != null ? new PhysicalLocation { ArtifactLocation = new ArtifactLocation { Uri = uri }, } : null; var notification = new Notification { Locations = new List <Location> { new Location { PhysicalLocation = physicalLocation } }, Level = level, Message = new Message { Text = message }, Exception = exceptionData }; if (!string.IsNullOrWhiteSpace(notificationId)) { notification.Descriptor = new ReportingDescriptorReference { Id = notificationId, }; } if (!string.IsNullOrWhiteSpace(ruleId)) { notification.AssociatedRule = new ReportingDescriptorReference { Id = ruleId, }; } return(notification); }
public static Notification CreateNotification( Uri uri, string notificationId, string ruleId, FailureLevel level, Exception exception, bool persistExceptionStack, string messageFormat, params string[] args) { messageFormat = messageFormat ?? GetMessageFormatResourceForNotification(notificationId); string message = string.Format(CultureInfo.CurrentCulture, messageFormat, args); ExceptionData exceptionData = exception != null && persistExceptionStack ? ExceptionData.Create(exception) : null; PhysicalLocation physicalLocation = uri != null ? new PhysicalLocation { ArtifactLocation = new ArtifactLocation { Uri = uri }, } : null; if (exceptionData != null) { physicalLocation ??= exceptionData.Stack?.Frames?[0].Location?.PhysicalLocation; } var notification = new Notification { Locations = new List <Location> { new Location { PhysicalLocation = physicalLocation } }, Level = level, Message = new Message { Text = message }, Exception = exceptionData, }; if (!string.IsNullOrWhiteSpace(notificationId)) { notification.Descriptor = new ReportingDescriptorReference { Id = notificationId, }; } if (!string.IsNullOrWhiteSpace(ruleId)) { notification.AssociatedRule = new ReportingDescriptorReference { Id = ruleId, }; } return(notification); }