/// <summary> /// Initializes a new instance of the <see cref="T:Coding4Fun.VisualStudio.ApplicationInsights.Channel.PersistenceChannel" /> class. /// </summary> /// <param name="storage"> /// A persistent storage that will store all transmissions. /// Setting this value groups channels, even from different processes. /// If 2 (or more) channels has the same <c>storage that share the same underlying folder</c> only one channel will perform the sending even if the channel is in a different process/AppDomain/Thread. /// </param> /// <param name="processLockFactory"> /// IProcessLockFactory that creates an IProcessLock to sync transmission between processes /// </param> /// <param name="sendersCount"> /// Defines the number of senders. A sender is a long-running thread that sends telemetry batches in intervals defined by <see cref="P:Coding4Fun.VisualStudio.ApplicationInsights.Channel.PersistenceChannel.SendingInterval" />. /// So the amount of senders also defined the maximum amount of http channels opened at the same time. /// By default we have 1 sending thread which should be more than enough for our purposes. /// </param> public PersistenceChannel(StorageBase storage, IProcessLockFactory processLockFactory, int sendersCount = 1) { TelemetryBuffer = new TelemetryBuffer(); this.storage = storage; Transmitter = new PersistenceTransmitter(this.storage, sendersCount, processLockFactory); flushManager = new FlushManager(this.storage, TelemetryBuffer); EndpointAddress = "https://dc.services.visualstudio.com/v2/track"; }
/// <summary> /// Initializes a new instance of the <see cref="T:Coding4Fun.VisualStudio.ApplicationInsights.Channel.Sender" /> class. /// </summary> /// <param name="storage">The storage that holds the transmissions to send.</param> /// <param name="transmitter"> /// The persistence transmitter that manages this Sender. /// The transmitter will be used as a configuration class, it exposes properties like SendingInterval that will be read by Sender. /// </param> /// <param name="startSending">A boolean value that determines if Sender should start sending immediately. This is only used for unit tests.</param> internal Sender(StorageBase storage, PersistenceTransmitter transmitter, bool startSending = true) { stopped = false; DelayHandler = new AutoResetEvent(false); stoppedHandler = new AutoResetEvent(false); drainingTimeout = TimeSpan.FromSeconds(100.0); this.transmitter = transmitter; this.storage = storage; if (startSending) { Task.Factory.StartNew(SendLoop, TaskCreationOptions.LongRunning).ContinueWith(delegate(Task t) { CoreEventSource.Log.LogVerbose("Sender: Failure in SendLoop: Exception: " + t.Exception.ToString()); LocalFileLoggerService.Default.Log(LocalLoggerSeverity.Error, "Telemetry", "Sender: Failure in SendLoop: Exception: " + t.Exception.Message); }, TaskContinuationOptions.OnlyOnFaulted); } }