protected override async Task WriteBatch(List<LogBatchEntry> batchEntries)
{
Argument.IsNotNull("batchEntries", batchEntries);
try
{
var textWriter = new StringWriter();
textWriter.Write("{\"events\":[");
var logEntries = batchEntries.Select(
batchEntry => FormatLogEvent(batchEntry.Log, batchEntry.Message, batchEntry.LogEvent, batchEntry.ExtraData, FastDateTime.Now))
.Aggregate((log1, log2) => string.Format("{0},{1}", log1, log2));
textWriter.Write(logEntries);
textWriter.Write("]}");
var message = textWriter.ToString();
lock (_lock)
{
if (_webClient == null)
{
var baseUri = ServerUrl;
if (!baseUri.EndsWith("/"))
{
baseUri += "/";
}
_webApiUrl = string.Format("{0}{1}", baseUri, BulkUploadResource);
_webClient = new WebClient {Encoding = Encoding.UTF8};
_webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
if (!string.IsNullOrWhiteSpace(ApiKey))
{
_webClient.Headers.Add(ApiKeyHeaderName, ApiKey);
}
}
}
_webClient.UploadString(_webApiUrl, message);
}
catch (Exception)
{
// Swallow
}
}