/// <summary> /// Save Log to the database /// </summary> /// <param name="log"></param> /// <returns></returns> public Task<int> Save(DivineLog log) { try { _ctx.DivineLogs.Add(log); SendToServiceBusQueue(log); return _ctx.SaveChangesAsync(); } catch (Exception ex) { string message = ex?.Message; Debug.WriteLine(message); Debug.WriteLine(ex); throw; // return Task.FromResult(0); } }
/// <summary> /// Save a log entry with a fire and forget procedure /// </summary> /// <param name="log">log entry to save</param> /// <returns>a bool task, true if successful and false if an exception is thrown</returns> public Task<int> Save(DivineLog log) { //this lock ensure that if another log is currently //saving another log, the lock will wait and retry //when the previous log entry has finish saving lock (fileLock) { try { //get full file path string fullPath = $"{FolderPath}DivineLog_{Utilities.CurrentDateTimeInEST.ToString("yyyyMMdd")}.txt"; return Task.Run(() => { File.AppendAllText(fullPath, log.ToString()); return 1; }); } catch { return Task.FromResult(0); } } }
protected Task SendToServiceBusQueue(DivineLog log) { var client = QueueClient.CreateFromConnectionString(serviceBusConnString, "DivineQueue"); var message = new BrokeredMessage(log.ToXML()); return client.SendAsync(message); }
public Task<int> Save(DivineLog log) { return Task.FromResult(1); }