public void ValidateLoggingIsWorking() { string instrumentationKey = "93d9c2b7-e633-4571-8520-d391511a1df5"; ApplicationInsightsAppenderTests.InitializeLog4NetAIAdapter(string.Format(@"<InstrumentationKey value=""{0}"" />", instrumentationKey)); // Set up error handler to intercept exception ApplicationInsightsAppender aiAppender = (ApplicationInsightsAppender)log4net.LogManager.GetRepository().GetAppenders()[0]; log4net.Util.OnlyOnceErrorHandler errorHandler = new log4net.Util.OnlyOnceErrorHandler(); aiAppender.ErrorHandler = errorHandler; // Log something ILog logger = log4net.LogManager.GetLogger("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); }
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); }
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"); }
private void VerifyPropertiesInTelemetry() { // Mock channel to validate that our appender is trying to send logs TelemetryConfiguration.Active.TelemetryChannel = this.adapterHelper.Channel; // Set up error handler to intercept exception ApplicationInsightsAppender aiAppender = (ApplicationInsightsAppender)LogManager.GetRepository().GetAppenders()[0]; OnlyOnceErrorHandler errorHandler = new OnlyOnceErrorHandler(); aiAppender.ErrorHandler = errorHandler; // Log something ILog logger = LogManager.GetLogger("TestAIAppender"); logger.Debug("Trace Debug"); ITelemetry[] sentItems = this.adapterHelper.Channel.SentItems; Assert.IsTrue(sentItems.Count() == 1); var telemetry = (TraceTelemetry)sentItems.First(); IDictionary<string, string> properties = telemetry.Properties; Assert.IsTrue(properties.Any()); string value; properties.TryGetValue("LoggerName", out value); Assert.AreEqual("TestAIAppender", value); Assert.IsTrue(properties.ContainsKey("ThreadName")); Assert.IsTrue(properties.ContainsKey("ClassName")); Assert.IsTrue(properties.ContainsKey("FileName")); Assert.IsTrue(properties.ContainsKey("MethodName")); Assert.IsTrue(properties.ContainsKey("LineNumber")); Assert.IsTrue(properties.ContainsKey("Domain")); }
private void SendMessagesToMockChannel(string instrumentationKey) { // Set up error handler to intercept exception ApplicationInsightsAppender aiAppender = (ApplicationInsightsAppender)log4net.LogManager.GetRepository().GetAppenders()[0]; log4net.Util.OnlyOnceErrorHandler errorHandler = new log4net.Util.OnlyOnceErrorHandler(); aiAppender.ErrorHandler = errorHandler; // Log something ILog logger = log4net.LogManager.GetLogger("TestAIAppender"); logger.Debug("Trace Debug"); logger.Error("Trace Error"); logger.Fatal("Trace Fatal"); logger.Info("Trace Info"); logger.Warn("Trace Warn"); AdapterHelper.ValidateChannel(this.adapterHelper, instrumentationKey, 5); }
/// <summary> /// Default constructor /// </summary> /// <remarks> /// <para>Empty default constructor</para> /// </remarks> protected AppenderSkeleton() { m_errorHandler = new OnlyOnceErrorHandler(this.GetType().Name); }