/// <inheritdoc /> public async Task WriteAsync(ILogPayload payload, CancellationToken cancellationToken = default) { if (payload != null) { var legalityEvents = LogEventSinkFilter.Filter(payload, _sinkConfiguration).ToList(); var logger = TencentCloudClsClientManager.GetClsClient(payload.Name, out var requestBaseUri, out var topicId); if (logger == null || string.IsNullOrWhiteSpace(requestBaseUri) || string.IsNullOrWhiteSpace(topicId)) { return; } var requestUri = $"http://{requestBaseUri}/structuredlog?topic_id={topicId}"; var clsLogPackage = TencentCloudClsFormatter.Format(legalityEvents, _sinkConfiguration.Rendering, _formatProvider); var content = new ByteArrayContent(clsLogPackage.ToByteArray()); content.Headers.Clear(); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(ContentType); var response = await logger.PostAsync(requestUri, content, cancellationToken); ProcessError(response, requestUri); } }
private static void RegisterTencentCloudClsClients(TencentCloudClsSinkOptions options) { if (!options.HasLegalNativeConfig(false)) { throw new InvalidOperationException("There is no legal JD Cloud Log Service native config."); } if (options.TencentCloudClsNativeConfigs.Any()) { foreach (var kvp in options.TencentCloudClsNativeConfigs) { TencentCloudClsClientManager.SetClsClient(kvp.Key, kvp.Value); } } else { TencentCloudClsClientManager.SetClsClient(Constants.DefaultClient, options.RequestUri, options.SecretId, options.SecretKey, options.TopicId, options.RequestTimeout, true); } }