/// <summary> /// Asynchronously adds a log to storage /// </summary> /// <param name="channelName">The name of the channel associated with the log</param> /// <param name="log">The log to add</param> /// <exception cref="StorageException"/> public Task PutLog(string channelName, Log log) { return(AddTaskToQueue(() => { var logJsonString = LogSerializer.Serialize(log); var logEntry = new LogEntry { Channel = channelName, Log = logJsonString }; _storageAdapter.InsertAsync(logEntry).GetAwaiter().GetResult(); })); }
/// <summary> /// Asynchronously adds a log to storage /// </summary> /// <param name="channelName">The name of the channel associated with the log</param> /// <param name="log">The log to add</param> /// <exception cref="StorageException"/> public async Task PutLogAsync(string channelName, Log log) { using (await _taskLockSource.GetTaskLockAsync().ConfigureAwait(false)) { var logJsonString = LogSerializer.Serialize(log); var logEntry = new LogEntry { Channel = channelName, Log = logJsonString }; await _storageAdapter.InsertAsync(logEntry).ConfigureAwait(false); } }
/// <summary> /// Asynchronously adds a log to storage /// </summary> /// <param name="channelName">The name of the channel associated with the log</param> /// <param name="log">The log to add</param> /// <exception cref="StorageException"/> public Task PutLog(string channelName, Log log) { var task = new Task(() => { var logJsonString = LogSerializer.Serialize(log); var logEntry = new LogEntry { Channel = channelName, Log = logJsonString }; _storageAdapter.InsertAsync(logEntry).Wait(); }); try { _queue.Add(task); } catch (InvalidOperationException) { throw new StorageException("The operation has been cancelled"); } _flushSemaphore.Release(); return(task); }