/// <summary> /// Emit a batch of log events, running to completion synchronously. /// </summary> /// <param name="events">The events to emit.</param> /// <remarks>Override either <see cref="PeriodicBatchingSink.EmitBatch"/> or <see cref="PeriodicBatchingSink.EmitBatchAsync"/>, /// not both.</remarks> protected override void EmitBatch(IEnumerable <LogEvent> events) { var operation = new TableBatchOperation(); var first = true; foreach (var logEvent in events) { if (first) { //check to make sure the partition key is not the same as the previous batch if (partitionKey != logEvent.Timestamp.Ticks) { batchRowId = 0; //the partitionkey has been reset partitionKey = logEvent.Timestamp.Ticks; //store the new partition key } first = false; } var logEventEntity = new LogEventEntity(logEvent, _formatProvider, partitionKey); logEventEntity.RowKey += "|" + batchRowId; operation.Add(TableOperation.Insert(logEventEntity)); batchRowId++; } _table.ExecuteBatch(operation); }
/// <summary> /// Emit a batch of log events, running to completion synchronously. /// </summary> /// <param name="events">The events to emit.</param> /// <remarks>Override either <see cref="PeriodicBatchingSink.EmitBatch"/> or <see cref="PeriodicBatchingSink.EmitBatchAsync"/>, /// not both.</remarks> protected override void EmitBatch(IEnumerable<LogEvent> events) { var operation = new TableBatchOperation(); var first = true; foreach (var logEvent in events) { if (first) { //check to make sure the partition key is not the same as the previous batch if (partitionKey != logEvent.Timestamp.Ticks) { batchRowId = 0; //the partitionkey has been reset partitionKey = logEvent.Timestamp.Ticks; //store the new partition key } first = false; } var logEventEntity = new LogEventEntity(logEvent, _formatProvider, partitionKey); logEventEntity.RowKey += "|" + batchRowId; operation.Add(TableOperation.Insert(logEventEntity)); batchRowId++; } _table.ExecuteBatch(operation); }
protected override async Task EmitBatchAsync(IEnumerable <LogEvent> events) { var table = _cloudTableProvider.GetCloudTable(_storageAccount, _storageTableName, _bypassTableCreationValidation); TableBatchOperation operation = new TableBatchOperation(); string lastPartitionKey = null; foreach (var logEvent in events) { var partitionKey = _keyGenerator.GeneratePartitionKey(logEvent); if (partitionKey != lastPartitionKey) { lastPartitionKey = partitionKey; if (operation.Count > 0) { await table.ExecuteBatchAsync(operation).ConfigureAwait(false); operation = new TableBatchOperation(); } } var logEventEntity = new LogEventEntity( logEvent, _formatProvider, partitionKey, _keyGenerator.GenerateRowKey(logEvent) ); operation.Add(TableOperation.Insert(logEventEntity)); } if (operation.Count > 0) { await table.ExecuteBatchAsync(operation).ConfigureAwait(false); } }
protected override async Task EmitBatchAsync(IEnumerable <LogEvent> events) { TableBatchOperation operation = new TableBatchOperation(); string lastPartitionKey = null; foreach (var logEvent in events) { var partitionKey = _keyGenerator.GeneratePartitionKey(logEvent); if (partitionKey != lastPartitionKey) { lastPartitionKey = partitionKey; if (operation.Count > 0) { await _table.ExecuteBatchAsync(operation); operation = new TableBatchOperation(); } } var logEventEntity = new LogEventEntity( logEvent, _formatProvider, partitionKey, _keyGenerator.GenerateRowKey(logEvent) ); operation.Add(TableOperation.Insert(logEventEntity)); } if (operation.Count > 0) { await _table.ExecuteBatchAsync(operation); } }
protected override async Task EmitBatchAsync(IEnumerable <LogEvent> events) { var operation = new TableBatchOperation(); var first = true; foreach (var logEvent in events) { if (first) { //check to make sure the partition key is not the same as the previous batch var ticks = logEvent.Timestamp.ToUniversalTime().Ticks; if (_partitionKey != ticks) { _batchRowId = 0; //the partitionkey has been reset _partitionKey = ticks; //store the new partition key } first = false; } var logEventEntity = new LogEventEntity(logEvent, _formatProvider, _partitionKey); logEventEntity.RowKey += "|" + _batchRowId; operation.Add(TableOperation.Insert(logEventEntity)); _batchRowId++; } await _table.ExecuteBatchAsync(operation); }
/// <summary> /// Emit the provided log event to the sink. /// </summary> /// <param name="logEvent">The log event to write.</param> public void Emit(LogEvent logEvent) { var logEventEntity = new LogEventEntity( logEvent, _formatProvider, logEvent.Timestamp.ToUniversalTime().Ticks); EnsureUniqueRowKey(logEventEntity); _table.Execute(TableOperation.Insert(logEventEntity)); }
/// <summary> /// Emit the provided log event to the sink. /// </summary> /// <param name="logEvent">The log event to write.</param> public void Emit(LogEvent logEvent) { var logEventEntity = new LogEventEntity( logEvent, _formatProvider, _keyGenerator.GeneratePartitionKey(logEvent), _keyGenerator.GenerateRowKey(logEvent) ); _table.ExecuteAsync(TableOperation.Insert(logEventEntity)) .SyncContextSafeWait(_waitTimeoutMilliseconds); }
/// <summary> /// Emit the provided log event to the sink. /// </summary> /// <param name="logEvent">The log event to write.</param> public void Emit(LogEvent logEvent) { var logEventEntity = new LogEventEntity( logEvent, _formatProvider, logEvent.Timestamp.ToUniversalTime().Ticks); EnsureUniqueRowKey(logEventEntity); _table.ExecuteAsync(TableOperation.Insert(logEventEntity)) .SyncContextSafeWait(_waitTimeoutMilliseconds); }
/// <summary> /// Emit the provided log event to the sink. /// </summary> /// <param name="logEvent">The log event to write.</param> public void Emit(LogEvent logEvent) { var table = _cloudTableProvider.GetCloudTable(_storageAccount, _storageTableName, _bypassTableCreationValidation); var logEventEntity = new LogEventEntity( logEvent, _textFormatter, _keyGenerator.GeneratePartitionKey(logEvent), _keyGenerator.GenerateRowKey(logEvent) ); table.ExecuteAsync(TableOperation.InsertOrMerge(logEventEntity)) .SyncContextSafeWait(_waitTimeoutMilliseconds); }