コード例 #1
0
		private bool ArchiveLogs(ServerFilesystemInfo archiveFs)
		{
			string archivePath = Path.Combine(archiveFs.Filesystem.FilesystemPath, "AlertLog");

			DateTime cutOffTime = Platform.Time.Date.AddDays(ServiceLockSettings.Default.AlertCachedDays*-1);
			AlertSelectCriteria criteria = new AlertSelectCriteria();
			criteria.InsertTime.LessThan(cutOffTime);
			criteria.InsertTime.SortAsc(0);

			using (ServerExecutionContext context = new ServerExecutionContext())
			{
				IAlertEntityBroker broker = context.ReadContext.GetBroker<IAlertEntityBroker>();

				ImageServerLogWriter<Alert> writer = new ImageServerLogWriter<Alert>(archivePath, "Alert");

				List<ServerEntityKey> keyList = new List<ServerEntityKey>(500);
				try
				{
					broker.Find(criteria, delegate(Alert result)
					                      	{
					                      		keyList.Add(result.Key);

					                      		// If configured, don't flush to disk.  We just delete the contents of keyList below.
					                      		if (!ServiceLockSettings.Default.AlertDelete)
					                      		{
					                      			if (writer.WriteLog(result, result.InsertTime))
					                      			{
					                      				// The logs been flushed, delete the log entries cached.
					                      				using (
					                      					IUpdateContext update =
					                      						PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush)
					                      					)
					                      				{
					                      					IApplicationLogEntityBroker updateBroker =
					                      						update.GetBroker<IApplicationLogEntityBroker>();
					                      					foreach (ServerEntityKey key in keyList)
					                      						updateBroker.Delete(key);
					                      					update.Commit();
					                      				}
					                      				keyList = new List<ServerEntityKey>();
					                      			}
					                      		}
					                      	});

					writer.FlushLog();

					if (keyList.Count > 0)
					{
						using (
							IUpdateContext update =
								PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
						{
							IAlertEntityBroker updateBroker = update.GetBroker<IAlertEntityBroker>();
							foreach (ServerEntityKey key in keyList)
								updateBroker.Delete(key);
							update.Commit();
						}
					}
				}
				catch (Exception e)
				{
					Platform.Log(LogLevel.Error, e, "Unexpected exception when purging Alert log files.");
					writer.Dispose();
					return false;
				}
				writer.Dispose();

				return true;
			}
		}
コード例 #2
0
		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;
			}
		}
コード例 #3
0
        private bool ArchiveLogs(ServerFilesystemInfo archiveFs)
        {
            string archivePath = Path.Combine(archiveFs.Filesystem.FilesystemPath, "AlertLog");

            DateTime            cutOffTime = Platform.Time.Date.AddDays(ServiceLockSettings.Default.AlertCachedDays * -1);
            AlertSelectCriteria criteria   = new AlertSelectCriteria();

            criteria.InsertTime.LessThan(cutOffTime);
            criteria.InsertTime.SortAsc(0);

            using (ServerExecutionContext context = new ServerExecutionContext())
            {
                IAlertEntityBroker broker = context.ReadContext.GetBroker <IAlertEntityBroker>();

                ImageServerLogWriter <Alert> writer = new ImageServerLogWriter <Alert>(archivePath, "Alert");

                List <ServerEntityKey> keyList = new List <ServerEntityKey>(500);
                try
                {
                    broker.Find(criteria, delegate(Alert result)
                    {
                        keyList.Add(result.Key);

                        // If configured, don't flush to disk.  We just delete the contents of keyList below.
                        if (!ServiceLockSettings.Default.AlertDelete)
                        {
                            if (writer.WriteLog(result, result.InsertTime))
                            {
                                // The logs been flushed, delete the log entries cached.
                                using (
                                    IUpdateContext update =
                                        PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush)
                                    )
                                {
                                    IApplicationLogEntityBroker updateBroker =
                                        update.GetBroker <IApplicationLogEntityBroker>();
                                    foreach (ServerEntityKey key in keyList)
                                    {
                                        updateBroker.Delete(key);
                                    }
                                    update.Commit();
                                }
                                keyList = new List <ServerEntityKey>();
                            }
                        }
                    });

                    writer.FlushLog();

                    if (keyList.Count > 0)
                    {
                        using (
                            IUpdateContext update =
                                PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
                        {
                            IAlertEntityBroker updateBroker = update.GetBroker <IAlertEntityBroker>();
                            foreach (ServerEntityKey key in keyList)
                            {
                                updateBroker.Delete(key);
                            }
                            update.Commit();
                        }
                    }
                }
                catch (Exception e)
                {
                    Platform.Log(LogLevel.Error, e, "Unexpected exception when purging Alert log files.");
                    writer.Dispose();
                    return(false);
                }
                writer.Dispose();

                return(true);
            }
        }
コード例 #4
0
        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);
            }
        }