public void WhenNotEnabledWithKeywordsAndEventWithSpecificKeywordIsRaised() { this.tableName = "WhenNotEnabledWithKeywordsAndEventWithSpecificKeywordIsRaised"; var connectionString = System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"]; AzureTableHelper.DeleteTable(connectionString, this.tableName); var logger = TestEventSource.Logger; TestScenario.With1Listener( logger, listener => { listener.LogToWindowsAzureTable("mytestinstance", connectionString, this.tableName, bufferingInterval: TimeSpan.FromSeconds(10)); listener.EnableEvents(logger, EventLevel.LogAlways); logger.ErrorWithKeywordDiagnostic("Error with keyword EventlogClassic"); }); var eventsCount = AzureTableHelper.GetEventsCount(connectionString, this.tableName); int eventCount = 0; #if EVENT_SOURCE_PACKAGE eventCount = 1; #endif Assert.AreEqual(eventCount, eventsCount); }
public void WhenBufferIntervalExceedsAndLessEntriesThanBufferCount() { this.tableName = "WhenBufferIntervalExceedsAndLessEntriesThanBufferCount"; var connectionString = System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"]; AzureTableHelper.DeleteTable(connectionString, this.tableName); var logger = TestEventSource.Logger; TestScenario.With1Listener( logger, listener => { var bufferingInterval = TimeSpan.FromSeconds(2); listener.LogToWindowsAzureTable("mytestinstance", connectionString, this.tableName, bufferingInterval: bufferingInterval); listener.EnableEvents(logger, EventLevel.Informational); // 100 events or more will be flushed by count before the buffering interval elapses for (int i = 0; i < 90; i++) { logger.Informational("Message1"); } // Wait for buffer interval to elapse and allow time for events to be written Task.Delay(bufferingInterval.Add(TimeSpan.FromSeconds(5))).Wait(); var events = AzureTableHelper.GetEventsCount(connectionString, this.tableName); Assert.AreEqual(90, events); }); }
public void WhenInternalBufferCountIsExceededAndIntervalExceeded() { this.tableName = "WhenInternalBufferCountIsExceededAndIntervalExceeded"; var connectionString = System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"]; AzureTableHelper.DeleteTable(connectionString, this.tableName); var logger = TestEventSource.Logger; TestScenario.With1Listener( logger, listener => { var bufferingInterval = TimeSpan.FromSeconds(5); listener.LogToWindowsAzureTable("mytestinstance", connectionString, this.tableName, bufferingInterval: bufferingInterval); listener.EnableEvents(logger, EventLevel.Informational); // When reachiing 100 events buffer will be flushed for (int i = 0; i < 110; i++) { logger.Informational("Message1"); } // Wait for buffer interval to elapse Task.Delay(bufferingInterval).Wait(); var events = AzureTableHelper.GetEventsCount(connectionString, this.tableName); Assert.AreEqual(100, events); }); // Last events should be written during the Dispose flush var eventsCountFinal = AzureTableHelper.GetEventsCount(connectionString, this.tableName); Assert.AreEqual(110, eventsCountFinal); }
public void WhenBufferingWithMinimumNonDefaultInterval() { this.tableName = "WhenBufferingWithMinimalNonDefaultInterval"; var connectionString = System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"]; AzureTableHelper.DeleteTable(connectionString, this.tableName); var logger = TestEventSource.Logger; TestScenario.With1Listener( logger, listener => { // Minimum buffering interval is 500 ms var minimumBufferingInterval = TimeSpan.FromMilliseconds(500); listener.LogToWindowsAzureTable("mytestinstance1", connectionString, this.tableName, bufferingInterval: minimumBufferingInterval); listener.EnableEvents(logger, EventLevel.LogAlways); var logTaskList = new List <Task>(); for (int i = 0; i < 10; i++) { logger.Critical("Critical message"); } // Wait for the events to be written and assert Task.Delay(TimeSpan.FromSeconds(3)).Wait(); var eventsCount = AzureTableHelper.GetEventsCount(connectionString, this.tableName); Assert.AreEqual(10, eventsCount); }); // No more events should be written during the Dispose flush var eventsCountFinal = AzureTableHelper.GetEventsCount(connectionString, this.tableName); Assert.AreEqual(10, eventsCountFinal); }
public void WhenSourceIsEnabledAndDisabled() { this.tableName = "WhenSourceIsEnabledAndDisabled"; var connectionString = System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"]; AzureTableHelper.DeleteTable(connectionString, this.tableName); var logger = TestEventSource.Logger; TestScenario.With1Listener( logger, listener => { listener.LogToWindowsAzureTable("mytestinstance", connectionString, this.tableName, bufferingInterval: TimeSpan.FromSeconds(1)); listener.EnableEvents(logger, EventLevel.LogAlways); logger.Critical("This is a critical message"); var events = AzureTableHelper.PollForEvents(connectionString, this.tableName, 1); Assert.AreEqual(1, events.Count()); listener.DisableEvents(logger); logger.Critical("This is a critical message"); }); var eventsCount = AzureTableHelper.GetEventsCount(connectionString, this.tableName); Assert.AreEqual(1, eventsCount); }
public void WhenNotEnabledWithKeywordsAndEventWithSpecificKeywordIsRaised() { this.tableName = "WhenNotEnabledWithKeywordsAndEventWithSpecificKeywordIsRaised"; var connectionString = System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"]; AzureTableHelper.DeleteTable(connectionString, this.tableName); var logger = TestEventSource.Logger; using (var listener = new ObservableEventListener()) { try { listener.LogToWindowsAzureTable("mytestinstance", connectionString, this.tableName, bufferingInterval: TimeSpan.FromSeconds(10)); listener.EnableEvents(logger, EventLevel.LogAlways); logger.ErrorWithKeywordDiagnostic("Error with keyword EventlogClassic"); } finally { listener.DisableEvents(logger); } } var eventsCount = AzureTableHelper.GetEventsCount(connectionString, this.tableName); Assert.AreEqual(0, eventsCount); }
public void WhenUsingNonDefaultBufferInterval() { this.tableName = "WhenUsingNonDefaultBufferInterval"; var connectionString = System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"]; AzureTableHelper.DeleteTable(connectionString, this.tableName); var logger = TestEventSource.Logger; using (var listener = new ObservableEventListener()) { try { var bufferingInterval = TimeSpan.FromSeconds(5); listener.LogToWindowsAzureTable("mytestinstance", connectionString, this.tableName, bufferingInterval: bufferingInterval); listener.EnableEvents(logger, EventLevel.LogAlways); // Pre-condition: Wait for the events to be written and assert Task.Delay(TimeSpan.FromSeconds(2)).Wait(); Assert.AreEqual(0, AzureTableHelper.GetEventsCount(connectionString, this.tableName)); for (int i = 0; i < 10; i++) { logger.Critical("Critical Message"); } // Event must not be written before the interval has elapsed Task.Delay(TimeSpan.FromSeconds(2)).Wait(); Assert.AreEqual(0, AzureTableHelper.GetEventsCount(connectionString, this.tableName)); // Wait for the buffer to flush at end of interval Task.Delay(bufferingInterval).Wait(); // 1st interval: Wait for the events to be written and assert Task.Delay(TimeSpan.FromSeconds(2)).Wait(); Assert.AreEqual(10, AzureTableHelper.GetEventsCount(connectionString, this.tableName)); } finally { listener.DisableEvents(logger); } } }
public void WhenEventsInThreeConsecutiveIntervals() { this.tableName = "WhenEventsInThreeConsecutiveIntervals"; var connectionString = System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"]; AzureTableHelper.DeleteTable(connectionString, this.tableName); var logger = TestEventSource.Logger; var bufferingInterval = TimeSpan.FromSeconds(6); var insertionInterval = TimeSpan.FromSeconds(2); TestScenario.With1Listener( logger, (listener, errorsListener) => { listener.LogToWindowsAzureTable("mytestinstance", connectionString, this.tableName, bufferingInterval: bufferingInterval); listener.EnableEvents(logger, EventLevel.Informational); // 1st interval: Log 10 events for (int i = 0; i < 10; i++) { logger.Informational("Message1"); } // 1st interval: Wait for the buffer to flush at end of interval Task.Delay(bufferingInterval).Wait(); // 2nd interval: start // 1st interval: Wait for the events to be written and assert Task.Delay(insertionInterval).Wait(); Assert.AreEqual(10, AzureTableHelper.GetEventsCount(connectionString, this.tableName)); // 2nd interval: Log 10 events for (int i = 0; i < 10; i++) { logger.Informational("Message1"); } // 2nd interval: Wait for the buffer to flush at end of interval Task.Delay(bufferingInterval).Wait(); // 3rd interval: start // 2nd interval: Wait for the events to be written and assert Task.Delay(insertionInterval).Wait(); Assert.AreEqual(20, AzureTableHelper.GetEventsCount(connectionString, this.tableName)); // 3rd interval: Log 10 events for (int i = 0; i < 10; i++) { logger.Informational("Message1"); } // 3rd interval: Wait for the buffer to flush at end of interval Task.Delay(bufferingInterval).Wait(); // 4th interval: start // 3rd interval: Wait for the events to be written and assert Task.Delay(insertionInterval).Wait(); Assert.AreEqual(30, AzureTableHelper.GetEventsCount(connectionString, this.tableName)); // No errors should have been reported Assert.AreEqual(string.Empty, errorsListener.ToString()); }); // No more events should have been written during the last flush in the Dispose Assert.AreEqual(30, AzureTableHelper.GetEventsCount(connectionString, this.tableName)); }