public int SelectCount() { ApplicationLogSelectCriteria criteria = GetSelectCriteria(); ResultCount = _searchController.GetApplicationLogCount(criteria); return(ResultCount); }
public IEnumerable <ApplicationLog> Select(int startRowIndex, int maximumRows) { if (maximumRows == 0) { return(new List <ApplicationLog>()); } ApplicationLogSelectCriteria criteria = GetSelectCriteria(); _list = _searchController.GetRangeLogs(criteria, startRowIndex, maximumRows); return(_list); }
private ApplicationLogSelectCriteria GetSelectCriteria() { var criteria = new ApplicationLogSelectCriteria(); if (!String.IsNullOrEmpty(LogLevel)) { string key = LogLevel.Replace("*", "%"); key = key.Replace("?", "_"); key = "%" + key + "%"; criteria.LogLevel.Like(key); } QueryHelper.SetGuiStringCondition(criteria.Thread, Thread); QueryHelper.SetGuiStringCondition(criteria.Host, Host); QueryHelper.SetGuiStringCondition(criteria.Message, Message); if (!String.IsNullOrEmpty(Exception)) { string key = Exception.Replace("*", "%"); key = key.Replace("?", "_"); key = "%" + key + "%"; criteria.Exception.Like(key); } // Sort with the latest timestamp first criteria.Timestamp.SortDesc(0); if (StartDate.HasValue && EndDate.HasValue) { criteria.Timestamp.Between(StartDate.Value, EndDate.Value); } else if (StartDate.HasValue) { criteria.Timestamp.MoreThanOrEqualTo(StartDate.Value); } else if (EndDate.HasValue) { criteria.Timestamp.LessThanOrEqualTo(EndDate.Value); } return(criteria); }
public int GetApplicationLogCount(ApplicationLogSelectCriteria criteria) { return(_adaptor.GetCount(criteria)); }
public IList <ApplicationLog> GetRangeLogs(ApplicationLogSelectCriteria criteria, int startIndex, int maxRows) { return(_adaptor.GetRange(criteria, startIndex, maxRows)); }
private static bool ArchiveTimeRange(ImageServerLogWriter <ApplicationLog> writer, DateTime cutOffTime) { ApplicationLogSelectCriteria criteria = new ApplicationLogSelectCriteria(); criteria.Timestamp.LessThan(cutOffTime); criteria.Timestamp.SortAsc(0); using (ServerExecutionContext context = new ServerExecutionContext()) { IApplicationLogEntityBroker broker = context.ReadContext.GetBroker <IApplicationLogEntityBroker>(); List <ServerEntityKey> keyList = new List <ServerEntityKey>(1000); try { broker.Find(criteria, delegate(ApplicationLog result) { keyList.Add(result.Key); if (writer.WriteLog(result, result.Timestamp)) { // The logs been flushed, delete the log entries cached. // Purposely use a read context here, even though we're doing // an update, so we don't use transaction wrappers, optimization // is more important at this point. using ( IReadContext update = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { IApplicationLogEntityBroker updateBroker = update.GetBroker <IApplicationLogEntityBroker>(); foreach (ServerEntityKey key in keyList) { updateBroker.Delete(key); } } keyList = new List <ServerEntityKey>(1000); } }); if (keyList.Count > 0) { // Purposely use a read context here, even though we're doing an update, so we // don't have to do an explicit commit and don't use transaction wrappers. using ( IReadContext update = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { IApplicationLogEntityBroker updateBroker = update.GetBroker <IApplicationLogEntityBroker>(); foreach (ServerEntityKey key in keyList) { updateBroker.Delete(key); } } } } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexpected exception when purging log files."); return(false); } return(true); } }
private bool ArchiveLogs(ServerFilesystemInfo archiveFs) { try { using (ServerExecutionContext context = new ServerExecutionContext()) { string archivePath = Path.Combine(archiveFs.Filesystem.FilesystemPath, "ApplicationLog"); ApplicationLogSelectCriteria criteria = new ApplicationLogSelectCriteria(); criteria.Timestamp.SortAsc(0); IApplicationLogEntityBroker broker = context.ReadContext.GetBroker <IApplicationLogEntityBroker>(); ApplicationLog firstLog = broker.FindOne(criteria); if (firstLog == null) { return(true); } DateTime currentCutOffTime = firstLog.Timestamp.AddMinutes(5); int cachedDays = ServiceLockSettings.Default.ApplicationLogCachedDays; if (cachedDays < 0) { cachedDays = 0; } DateTime cutOffTime = Platform.Time.Date.AddDays(cachedDays * -1); if (currentCutOffTime > cutOffTime) { return(true); } using ( ImageServerLogWriter <ApplicationLog> writer = new ImageServerLogWriter <ApplicationLog>(archivePath, "ApplicationLog")) { while (currentCutOffTime < cutOffTime) { if (!ArchiveTimeRange(writer, currentCutOffTime)) { writer.FlushLog(); return(false); } currentCutOffTime = currentCutOffTime.AddMinutes(5); } // Now flush the last potential 5 minutes. if (!ArchiveTimeRange(writer, cutOffTime)) { writer.FlushLog(); return(false); } writer.FlushLog(); } return(true); } } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexpected exception when writing log file."); return(false); } }