private async Task<bool> LogItemAsync(LogItem logItem) { LogDataContext logDataContext = new LogDataContext(logItem.LogType, _storageAccount); bool response = await logDataContext.LogActivity(logItem); return response; }
public async Task<bool> LogActivity(LogItem logItem) { var tableStorage = new CloudTableClient(_storageAccount.TableEndpoint.AbsoluteUri, _storageAccount.Credentials); #region Update to Parallel Tasks (not consistent) /* List<Task> tasks = new List<Task>(); tasks.Add(Task.Factory.StartNew(() => logItemTask("byactivity", logItem))); tasks.Add(Task.Factory.StartNew(() => logItemTask("bytime", logItem))); tasks.Add(Task.Factory.StartNew(() => logItemTask("byip", logItem))); tasks.Add(Task.Factory.StartNew(() => logItemTask("byuser", logItem))); Task.WaitAll(tasks.ToArray()); */ #endregion #region Non Parallel logItemTask("byactivity", logItem); logItemTask("bytime", logItem); logItemTask("byip", logItem); logItemTask("byuser", logItem); #endregion return true; }
public async Task<bool> LogAsync(UserProfile userProfile, string logType, string logSubType, string description, HttpRequestBase request) { LogItem logItem = new LogItem(); logItem.LogType = logType; logItem.LogSubtype = logSubType; logItem.Company = userProfile.Company; logItem.UserName = userProfile.UserName; logItem.Email = userProfile.Email; logItem.Description = description; try { logItem.IPAddress = (request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim().Split(':')[0].ToString(); } catch { logItem.IPAddress = "null"; } LoggingDataService loggingDataService = new LoggingDataService(); return await loggingDataService.LogItemAsync(logItem); }
private async Task<bool> logItemTask(string logType, LogItem logItem) { switch (logType) { case "byactivity": try { // 1. Store by Activity: =================================================================== //[logtype]logbyactivity LogByActivityTableEntity logByActivityTableEntity = new LogByActivityTableEntity(); logByActivityTableEntity.ActivityType = logItem.LogSubtype; logByActivityTableEntity.UserName = logItem.UserName; logByActivityTableEntity.IPAddress = logItem.IPAddress; logByActivityTableEntity.Description = logItem.Description; logByActivityTableEntity.Company = logItem.Company; logByActivityTableEntity.Email = logItem.Email; AddObject(_tableName + "byactivity" + EnvironmentSettings.Environment.Current, logByActivityTableEntity); SaveChanges(); return true; } catch (Exception e) { return false; } case "byip": try { // 2. Store by IP: =================================================================== //[logtype]logbyip LogByIPAddressTableEntity logByIPAddressTableEntity = new LogByIPAddressTableEntity(); logByIPAddressTableEntity.ActivityType = logItem.LogSubtype; logByIPAddressTableEntity.UserName = logItem.UserName; logByIPAddressTableEntity.IPAddress = logItem.IPAddress; logByIPAddressTableEntity.Description = logItem.Description; logByIPAddressTableEntity.Company = logItem.Company; logByIPAddressTableEntity.Email = logItem.Email; AddObject(_tableName + "byip" + EnvironmentSettings.Environment.Current, logByIPAddressTableEntity); SaveChanges(); return true; } catch(Exception e) { return false; } case "byuser": try { // 3. Store by User: =================================================================== //[logtype]logbyuser LogByUserTableEntity logByUserTableEntity = new LogByUserTableEntity(); logByUserTableEntity.ActivityType = logItem.LogSubtype; logByUserTableEntity.UserName = logItem.UserName; logByUserTableEntity.IPAddress = logItem.IPAddress; logByUserTableEntity.Description = logItem.Description; logByUserTableEntity.Company = logItem.Company; logByUserTableEntity.Email = logItem.Email; AddObject(_tableName + "byuser" + EnvironmentSettings.Environment.Current, logByUserTableEntity); SaveChanges(); return true; } catch(Exception e) { return false; } case "bytime": try { // 4. Store by Time: =================================================================== //[logtype]logbytime LogByTimeTableEntity logByTimeTableEntity = new LogByTimeTableEntity(); logByTimeTableEntity.ActivityType = logItem.LogSubtype; logByTimeTableEntity.UserName = logItem.UserName; logByTimeTableEntity.IPAddress = logItem.IPAddress; logByTimeTableEntity.Description = logItem.Description; logByTimeTableEntity.Company = logItem.Company; logByTimeTableEntity.Email = logItem.Email; AddObject(_tableName + "bytime" + EnvironmentSettings.Environment.Current, logByTimeTableEntity); SaveChanges(); return true; } catch (Exception e) { return false; } default: return false; } }