/// <summary> /// Emit a batch of log events to Datadog logs-backend. /// </summary> /// <param name="events">The events to emit.</param> protected override async Task EmitBatchAsync(IEnumerable <LogEvent> events) { if (!events.Any()) { return; } var tasks = _client.WriteAsync(events); await Task.WhenAll(tasks).ConfigureAwait(false); }
private void SendBatch(Object state) { EnsureClient(); lock (_events) { try { _client.WriteAsync(new List <LogEventInfo>(_events)); _events.Clear(); } catch { } } }
/// <summary> /// Emit a batch of log events to Datadog logs-backend. /// </summary> /// <param name="events">The events to emit.</param> protected override async Task EmitBatchAsync(IEnumerable <LogEvent> events) { try { if (!events.Any()) { return; } var task = _client.WriteAsync(events); await RunTask(task); } catch (Exception e) { OnException(e); } }
/// <inheritdoc /> public async Task <bool> FlushAsync(MetricsDataValueSource metricsData, CancellationToken cancellationToken = default) { Logger.Trace("Flushing metrics snapshot"); DatadogWriteResult result; using (var stream = new MemoryStream()) { await Formatter.WriteAsync(stream, metricsData, cancellationToken); result = await _datadogClient.WriteAsync(Encoding.UTF8.GetString(stream.ToArray()), cancellationToken); } if (result.Success) { Logger.Trace("Flushed metrics snapshot"); return(true); } Logger.Error(result.ErrorMessage); return(false); }