protected override void Append(LoggingEvent loggingEvent) { var message = RenderLoggingEvent(loggingEvent); _client .SendAsync(WebHookUrl, new Payload { Username = Username, IconEmoji = IconEmoji, IconUrl = IconUrl, Text = message }) .ContinueWith(t => ErrorHandler.Error(t.Exception.ToString()), TaskContinuationOptions.OnlyOnFaulted); }
public async Task ProcessEventAsync(ISnEvent snEvent, CancellationToken cancel) { var node = snEvent.NodeEventArgs.SourceNode; // currently we deal with content-related events only if (node == null) { return; } var subscriptions = _subscriptionStore.GetRelevantSubscriptions(snEvent) .Where(si => si.Subscription.Enabled && si.Subscription.IsValid) .ToArray(); if (subscriptions.Any()) { _logger?.LogTrace($"Sending webhook events for subscriptions: " + $"{string.Join(", ", subscriptions.Select(si => si.Subscription.Name + " (" + si.EventType + ")"))}"); } //TODO: extend webhook request payload with event-specific info var eventArgs = snEvent.NodeEventArgs as NodeEventArgs; var previousVersion = eventArgs.GetPreviousVersion(); var sendingTasks = subscriptions .Select(si => _webHookClient.SendAsync( si.Subscription.Url, si.EventType.ToString(), node.Id, si.Subscription.Id, si.Subscription.HttpMethod, GetPayload(si.Subscription, si.EventType, node, previousVersion), si.Subscription.HttpHeaders, cancel)); //TODO: handle responses: webhook statistics implementation await sendingTasks.WhenAll().ConfigureAwait(false); }