public void TracesAreEnqueuedInChannel()
        {
            TelemetryConfiguration.Active.TelemetryChannel = this.adapterHelper.Channel;

            ApplicationInsightsAppenderTests.InitializeLog4NetAIAdapter(string.Empty);
            this.SendMessagesToMockChannel(this.adapterHelper.InstrumentationKey);
        }
Exemple #2
0
        public void InitializeAppenderDoesNotThrowLogExceptionWhenInstrumentationKeyIsCorrect()
        {
            string instrumentationKey = Guid.NewGuid().ToString();

            this.VerifyInitializationSuccess(
                () => ApplicationInsightsAppenderTests.InitializeLog4NetAIAdapter(string.Format(InvariantCulture, @"<InstrumentationKey value=""{0}"" />", instrumentationKey)),
                instrumentationKey);
        }
Exemple #3
0
        public void TracesAreEnqueuedInChannel()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            TelemetryConfiguration.Active.InstrumentationKey = this.adapterHelper.InstrumentationKey;
            TelemetryConfiguration.Active.TelemetryChannel   = this.adapterHelper.Channel;
#pragma warning restore CS0618 // Type or member is obsolete

            ApplicationInsightsAppenderTests.InitializeLog4NetAIAdapter(string.Empty);
            this.SendMessagesToMockChannel(this.adapterHelper.InstrumentationKey);
        }
        public void InstrumentationKeyCanBeOverridden()
        {
            TelemetryConfiguration.Active.TelemetryChannel = this.adapterHelper.Channel;

            // Set instrumentation key in Log4Net environment
            string instrumentationKey = "93d9c2b7-e633-4571-8520-d391511a1df5";

            ApplicationInsightsAppenderTests.InitializeLog4NetAIAdapter(string.Format(@"<InstrumentationKey value=""{0}"" />", instrumentationKey));
            Assert.AreNotEqual(instrumentationKey, this.adapterHelper.InstrumentationKey, "This test will not verify anything if the same instrumentation key is used by both");
            this.SendMessagesToMockChannel(instrumentationKey);
        }
            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");
            }
Exemple #6
0
            public AppendableLogger()
            {
                this.adapterHelper = new AdapterHelper();

                // Mock channel to validate that our appender is trying to send logs
#pragma warning disable CS0618 // Type or member is obsolete
                TelemetryConfiguration.Active.TelemetryChannel = this.adapterHelper.Channel;
#pragma warning restore CS0618 // Type or member is obsolete

                ApplicationInsightsAppenderTests.InitializeLog4NetAIAdapter(string.Empty);

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

                this.Logger = LogManager.GetLogger(callingAssembly, "TestAIAppender");
            }
Exemple #7
0
        public void ValidateLoggingIsWorking()
        {
            string instrumentationKey = "93d9c2b7-e633-4571-8520-d391511a1df5";

            ApplicationInsightsAppenderTests.InitializeLog4NetAIAdapter(string.Format(InvariantCulture, @"<InstrumentationKey value=""{0}"" />", instrumentationKey));

            // Set up error handler to intercept exception
            ApplicationInsightsAppender aiAppender = (ApplicationInsightsAppender)log4net.LogManager.GetRepository(callingAssembly).GetAppenders()[0];

            log4net.Util.OnlyOnceErrorHandler errorHandler = new log4net.Util.OnlyOnceErrorHandler();
            aiAppender.ErrorHandler = errorHandler;

            // Log something
            ILog logger = log4net.LogManager.GetLogger(callingAssembly, "TestAIAppender");

            for (int i = 0; i < 1500; i++)
            {
                logger.Debug("Trace Debug" + i + DateTime.Now);
            }

            Assert.AreEqual(instrumentationKey, aiAppender.TelemetryClient.Context.InstrumentationKey);
            Assert.IsNull(errorHandler.Exception);
        }
Exemple #8
0
 public void InitializeAppenderNotFailingWhenInstrumentionKeyIsEmptyString()
 {
     this.VerifyInitializationSuccess(
         () => ApplicationInsightsAppenderTests.InitializeLog4NetAIAdapter(@"<InstrumentationKey value="""" />"),
         string.Empty);
 }
Exemple #9
0
 public void Log4NetAddsCustomPropertiesToTraceTelemetry()
 {
     ApplicationInsightsAppenderTests.InitializeLog4NetAIAdapter(string.Empty);
     this.VerifyPropertiesInTelemetry();
 }