public async void EmitAsync() { try { using (await _lock.LockAsync()) { //Check to see if we have any held events if (_events.Count > 0) { //Create a request var request = new SubmitApplicationLogsRequest { Events = _events.ToArray(), IsFirst = _isFirstBatch }; _logger.Verbose($"Emitting application logs with {_events.Count} events."); //Upload the logs!!!!!! await _deviceApiClient.ApplicationLogs.SubmitLogsAsync(request); _isFirstBatch = false; //Clear out the events that we just sent. Keep the same list instance so that we // don't keep allocating memory. _events.Clear(); } } } catch (Exception e) { _logger.Warning(e, "Emit Error: " + e); } }
public void Post([FromBody] SubmitApplicationLogsRequest request) { using (var connection = _connectionFactory.CreateAndOpen()) using (var transaction = connection.BeginTransaction()) { //If this is the first batch, we'll go ahead and kill the existing entries. if (request.IsFirst) { const string deleteSql = "delete from ApplicationLogs where DeviceId = @deviceId"; connection.Execute(deleteSql, new { deviceId = DeviceId }, transaction); } //Transform the request into something we can insert. var entries = request.Events .Select(e => new ApplicationLog { Id = Guid.NewGuid(), Type = e.Type, Message = e.Content, DeviceId = DeviceId, CreatedLocal = e.TimestampLocal, CreatedUtc = e.TimestampUtc }); //Insert these guys foreach (var entry in entries) { connection.Insert(entry, transaction); } transaction.Commit(); } }
public Task SubmitLogsAsync(SubmitApplicationLogsRequest request, CancellationToken cancellationToken = new CancellationToken()) { return(_client.MakeRequestAsync( cancellationToken, HttpMethod.Post, ResourceUris.ApplicationLogs, headers: _tokenFactory.CreateRequestHeaders(), content: request.ToJsonContent())); }