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/11/22 23:41:46 UTC

cvs commit: logging-log4net/src/Appender FileAppender.cs

nicko       2004/11/22 14:41:46

  Modified:    src/Appender FileAppender.cs
  Log:
  Added check to FileAppender.OpenFile to ensure that the file path is fully qualified
  
  Revision  Changes    Path
  1.9       +19 -3     logging-log4net/src/Appender/FileAppender.cs
  
  Index: FileAppender.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Appender/FileAppender.cs,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FileAppender.cs	22 Nov 2004 02:09:06 -0000	1.8
  +++ FileAppender.cs	22 Nov 2004 22:41:46 -0000	1.9
  @@ -91,7 +91,9 @@
   		public FileAppender(ILayout layout, string filename, bool append) 
   		{
   			Layout = layout;
  -			SafeOpenFile(filename, append);
  +			File = filename;
  +			AppendToFile = append;
  +			ActivateOptions();
   		}
   
   		/// <summary>
  @@ -295,7 +297,7 @@
   		/// <summary>
   		/// Sets and <i>opens</i> the file where the log output will go. The specified file must be writable.
   		/// </summary>
  -		/// <param name="fileName">The path to the log file</param>
  +		/// <param name="fileName">The path to the log file. Must be a fully qualified path.</param>
   		/// <param name="append">If true will append to fileName. Otherwise will truncate fileName</param>
   		/// <remarks>
   		/// <para>
  @@ -318,7 +320,7 @@
   		/// <summary>
   		/// Sets and <i>opens</i> the file where the log output will go. The specified file must be writable.
   		/// </summary>
  -		/// <param name="fileName">The path to the log file</param>
  +		/// <param name="fileName">The path to the log file. Must be a fully qualified path.</param>
   		/// <param name="append">If true will append to fileName. Otherwise will truncate fileName</param>
   		/// <remarks>
   		/// <para>
  @@ -332,6 +334,20 @@
   		/// </remarks>
   		virtual protected void OpenFile(string fileName, bool append)
   		{
  +			if (LogLog.IsErrorEnabled)
  +			{
  +				// Internal check that the fileName passed in is a rooted path
  +				bool isPathRooted = false;
  +				using(SecurityContext.Impersonate(this))
  +				{
  +					isPathRooted = Path.IsPathRooted(fileName);
  +				}
  +				if (!isPathRooted)
  +				{
  +					LogLog.Error("FileAppender: INTERNAL ERROR. SafeOpenFile("+fileName+"): File name is not fully qualified.");
  +				}
  +			}
  +
   			lock(this)
   			{
   				Reset();