using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.Channel; namespace PlanTempus.Core.Telemetry { public class SeqTelemetryChannel : InMemoryChannel, ITelemetryChannel { private readonly IMessageChannel _messageChannel; private readonly TelemetryClient _telemetryClient; public SeqTelemetryChannel(IMessageChannel messageChannel, TelemetryClient telemetryClient) { _messageChannel = messageChannel; _telemetryClient = telemetryClient; } public new void Send(ITelemetry telemetry) { if (telemetry.Context.GlobalProperties["OmitSeqTelemetryChannel"] != "true") try { var writeTask = _messageChannel.Writer.WriteAsync(telemetry).AsTask(); writeTask.ContinueWith(t => { if (t.Exception != null) { throw t.Exception; } }, TaskContinuationOptions.OnlyOnFaulted); } catch (Exception e) { _telemetryClient.TrackException(e, new Dictionary { { "OmitSeqTelemetryChannel", "true" } }); } base.Send(telemetry); } } }