public async Task EmitBatchEchoesLogsApiReturnValue(bool logsApiResponse) { var mutex = new ManualResetEventSlim(); bool LogsSentCallback(int x) { mutex.Set(); return(logsApiResponse); } var logsApi = new TestLogsApi(LogsSentCallback); var options = new BatchingSinkOptions(batchSizeLimit: 2, queueLimit: DefaultQueueLimit, period: TinyWait); var sink = new TestSink(logsApi, LogSettingsHelper.GetFormatter(), options); sink.Start(); var log = new TestLogEvent(DirectSubmissionLogLevel.Debug, "First message"); var queue = new Queue <DatadogLogEvent>(); queue.Enqueue(log); var result = await sink.CallEmitBatch(queue); result.Should().Be(logsApiResponse); }
/// <summary> /// Logs a message. /// </summary> /// <param name="level">Log level.</param> /// <param name="message">Log message.</param> /// <param name="args">Message arguments.</param> public void LogMessage(LogLevel level, string message, params object[] args) { string formatted = string.Format( CultureInfo.InvariantCulture, message, args); if (WriteToConsole) { Console.WriteLine(formatted); } TestLogEvent logEvent = new TestLogEvent(level, formatted); _events.Add(logEvent); }
private void UpdateLog(TestLogEvent test, ItemCheckEventArgs e) { // If the check state has changed. if (e.NewValue != e.CurrentValue) { switch (e.NewValue) { case CheckState.Checked: // The new state is checked: add the checked log items. int indexEvt = 0; // Index for the events. int indexItem = 0; // Index for the log items. while ((indexEvt < this.events.Count) && (indexItem < this.listView.Items.Count)) { // Get the event at the current log item. LogEvent evt = this.listView.Items[indexItem].Tag as LogEvent; // If the current event matches the type if (test(this.events[indexEvt])) { // If the current event has a timestamp smaller than the current item. if (this.events[indexEvt].Timestamp < evt.Timestamp) { // Insert the event at the current item position this.listView.Items.Insert(indexItem, this.events[indexEvt].Tag as ListViewItem); // Increment the event index. indexEvt++; } // Else, increment the item index. else indexItem++; } // Else, increment the event index. else indexEvt++; } // If there are events remaining. for (; indexEvt < this.events.Count; indexEvt++) { // If the current event matches the type if (test(this.events[indexEvt])) { // Append the event. this.listView.Items.Add(this.events[indexEvt].Tag as ListViewItem); } } break; case CheckState.Unchecked: // The new state is unchecked: remove the uncheked log items. for (int index = 0; index < this.listView.Items.Count; ) { // Get the log event. LogEvent evt = this.listView.Items[index].Tag as LogEvent; // If the type matches, remove the log item. if (test(evt)) this.listView.Items.RemoveAt(index); // Else, increment the index else index++; } break; } } }