public HttpResponseMessage AddBatchLogs(IEnumerable <SyncLogEntry> logBatch)
        {
            var siteId = User.Identity.GetClaim(CustomClaimTypes.SiteId);

            var res          = HttpStatusCode.NoContent; //204, response successfully processed with no content to return
            var errorMessage = "";

            if (logBatch == null || logBatch.Count() == 0)
            {
                errorMessage = "An empty or null collection was transmitted, no logs were added.";
            }
            else
            {
                try
                {
                    SyncLogEntryUtil.AddBulkLogs(logBatch, siteId);
                }
                catch (Exception ex)
                {
                    res = HttpStatusCode.InternalServerError;
                    Logging.WriteToAppLog("Error processing SyncLogUpdateController/AddBatchLogs", System.Diagnostics.EventLogEntryType.Error, ex);
                    errorMessage = string.Format("An error occurred processing the request, check the system event log for details ({0}).", ex.Message);
                }
            }

            HttpResponseMessage response = Request.CreateResponse(res);

            response.Headers.Add("ErrorMessage", errorMessage);
            return(response);
        }
        public async Task <bool> AddLogEntry(SyncLogEntry log)
        {
            var siteId = User.Identity.GetClaim(CustomClaimTypes.SiteId);

            log.RemoteSiteID = siteId;
            return(await SyncLogEntryUtil.AddLog(log));
        }
Exemple #3
0
        public async Task <Dashboard> Logs()
        {
            var data         = new Dashboard();
            var siteActivity = await SyncLogEntryUtil.GetLogs(1);

            var sites = await RemoteSiteUtil.GetAllSites();

            var lastLog = siteActivity
                          .OrderByDescending(s => s.LogDate)
                          .FirstOrDefault();

            data.LastSiteActivity = lastLog?.LogDate;

            data.LatestLogs = siteActivity
                              .Where(l => l.ErrorType == "Error")
                              .OrderByDescending(l => l.LogDate)
                              .Take(5)
                              .Select(l => new Dashboard.DashLog(l, sites))
                              .ToList();

            var lastUserActivity = siteActivity
                                   .Where(u => u.StagedUserId != null)
                                   .OrderByDescending(u => u.LogDate)
                                   .FirstOrDefault();

            data.LastUserSync = lastUserActivity?.LogDate;

            return(data);
        }
        public static void ProcessLogQueue([QueueTrigger("logbatch")] string queueData, IBinder binder)
        {
            try
            {
                string        data             = queueData;
                string        containerAndBlob = "";
                BlobAttribute blobAttribute;
                if (Uri.IsWellFormedUriString(queueData, UriKind.Absolute))
                {
                    var uri = new Uri(queueData);
                    containerAndBlob = uri.AbsolutePath.Substring(1);

                    blobAttribute = new BlobAttribute(containerAndBlob, FileAccess.Read);
                    data          = queueData;
                    using (var stream = binder.Bind <Stream>(blobAttribute))
                    {
                        StreamReader reader = new StreamReader(stream);
                        data = reader.ReadToEnd();
                    }
                }

                IEnumerable <SyncLogEntry> logBatch = JsonConvert.DeserializeObject <IEnumerable <SyncLogEntry> >(data);

                var res = SyncLogEntryUtil.ProcessCollection(logBatch);

                if (containerAndBlob.Length > 0)
                {
                    //delete block blob
                    //Must be "FileAccess.ReadWrite"
                    blobAttribute = new BlobAttribute(containerAndBlob, FileAccess.ReadWrite);
                    var blockBlob = binder.Bind <CloudBlockBlob>(blobAttribute);
                    blockBlob.DeleteIfExists();
                }
            }
            catch (Exception ex)
            {
                Logging.WriteToAppLog("Error processing queue 'logbatch'", System.Diagnostics.EventLogEntryType.Error, ex);
            }
        }
        public static void WriteToSyncLog(string source, string detail, EventLogEntryType errorType, Exception ex = null)
        {
            var status = errorType.ToString();

            if (ex != null)
            {
                detail += GetFormattedException(ex);
            }

            var log = new SyncLogEntry
            {
                Detail    = detail,
                Source    = source,
                ErrorType = status
            };

            bool res  = false;
            var  task = Task.Run(async() => {
                res = await SyncLogEntryUtil.AddLog(log);
            });

            task.Wait();
        }
Exemple #6
0
        public async Task <IEnumerable <SyncLogEntry> > GetLogsByUser(string userId, int?days = null)
        {
            var res = await SyncLogEntryUtil.GetLogsByUser(userId, days);

            return(res.OrderByDescending(l => l.LogDate).ToList());
        }