public static void ValidateChannel(AdapterHelper adapterHelper, string instrumentationKey, int expectedTraceCount)
        {
            // Validate that the channel received traces
            ITelemetry[] sentItems = null;
            int totalMillisecondsToWait = (int)TimeSpan.FromMinutes(1).TotalMilliseconds;
            const int IterationMilliseconds = 250;

            while (totalMillisecondsToWait > 0)
            {
                sentItems = adapterHelper.Channel.SentItems;
                if (sentItems.Length > 0)
                {
                    ITelemetry telemetry = sentItems.FirstOrDefault();

                    Assert.AreEqual(expectedTraceCount, sentItems.Length, "All messages are received by the channel");
                    Assert.IsNotNull(telemetry, "telemetry collection is not null");
                    Assert.AreEqual(instrumentationKey, telemetry.Context.InstrumentationKey, "The correct instrumentation key was used");
                    break;
                }

                Thread.Sleep(IterationMilliseconds);
                totalMillisecondsToWait -= IterationMilliseconds;
            }

            Assert.IsNotNull(sentItems);
            Assert.IsTrue(sentItems.Length > 0);
        }
 public void Initialize()
 {
     this.adapterHelper = new AdapterHelper();
     this.appendableLogger = new AppendableLogger();
 }
            public AppendableLogger()
            {
                this.adapterHelper = new AdapterHelper();

                // Mock channel to validate that our appender is trying to send logs
                TelemetryConfiguration.Active.TelemetryChannel = this.adapterHelper.Channel;

                ApplicationInsightsAppenderTests.InitializeLog4NetAIAdapter(string.Empty);

                // Set up error handler to intercept exception
                var aiAppender = (ApplicationInsightsAppender)LogManager.GetRepository().GetAppenders()[0];
                var errorHandler = new OnlyOnceErrorHandler();
                aiAppender.ErrorHandler = errorHandler;

                this.Logger = LogManager.GetLogger("TestAIAppender");
            }
 public void Initialize()
 {
     this.adapterHelper = new AdapterHelper();
 }