You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by ni...@apache.org on 2004/08/20 00:26:33 UTC

cvs commit: logging-log4net/src/Util SystemInfo.cs

nicko       2004/08/19 15:26:32

  Modified:    src/Util SystemInfo.cs
  Log:
  Added ProcessStartTime property
  
  Revision  Changes    Path
  1.6       +37 -0     logging-log4net/src/Util/SystemInfo.cs
  
  Index: SystemInfo.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Util/SystemInfo.cs,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SystemInfo.cs	7 Jun 2004 00:57:31 -0000	1.5
  +++ SystemInfo.cs	19 Aug 2004 22:26:31 -0000	1.6
  @@ -258,6 +258,43 @@
   			}
   		}
   
  +		private static DateTime s_processStartTime = DateTime.MinValue;
  +
  +		/// <summary>
  +		/// Get the start time for the current process.
  +		/// </summary>
  +		/// <remarks>
  +		/// <para>
  +		/// Tries to get the start time for the current process.
  +		/// Failing that it returns the time of the first call to
  +		/// this property.
  +		/// </para>
  +		/// <para>
  +		/// Note that AppDomains may be loaded and unloaded within the
  +		/// same process without the process terminating and therefore
  +		/// without the process start time being reset.
  +		/// </para>
  +		/// </remarks>
  +		public static DateTime ProcessStartTime
  +		{
  +			get
  +			{
  +				if (s_processStartTime == DateTime.MinValue)
  +				{
  +					try
  +					{
  +						s_processStartTime = System.Diagnostics.Process.GetCurrentProcess().StartTime;
  +					}
  +					catch
  +					{
  +						// Unable to get the start time, use now as the start time
  +						s_processStartTime = DateTime.Now;
  +					}
  +				}
  +				return s_processStartTime;
  +			}
  +		}
  +
   		#endregion Public Static Properties
   
   		#region Public Static Methods