Hi,

 

This is the exact same operation as the file mode does:

 

FileMode fileOpenMode = m_append ? FileMode.Append : FileMode.Create;

 

Hence this patch is completely useless. Parent directories are already
created:

                            if (!Directory.Exists(directoryFullName))
                            {
 
Directory.CreateDirectory(directoryFullName);
                            }

 

  _____  

From: Pie Lee [mailto:haperk...@gmail.com] 
Sent: Wednesday, November 10, 2010 2:59 AM
To: log4net-dev@logging.apache.org
Subject: suggestion for Log4Net 1.2.10

 

 Hi, ALL

Find that if the rolling file path do not exist, the appender will do
nothing (you will get confused what is wrong......)

I think it had better create the corresponding directory and file.

So I change the code at Log4net--Appender--FileAppender.cs

            public override Stream AcquireLock()
            {
                if (m_stream==null)
                {
                    try
                    {
 
using(CurrentAppender.SecurityContext.Impersonate(this))
                        {
                            // Ensure that the directory structure exists
                            string directoryFullName =
Path.GetDirectoryName(m_filename);

                            // Only create the directory if it does not
exist
                            // doing this check here resolves some
permissions failures
                            if (!Directory.Exists(directoryFullName))
                            {
 
Directory.CreateDirectory(directoryFullName);
                            }
     
                            //added by me
                            if (!System.IO.File.Exists(m_filename))
                            {
                                System.IO.File.Create(m_filename).Close();
                            }

                            FileMode fileOpenMode = m_append ?
FileMode.Append : FileMode.Create;
                            m_stream = new FileStream(m_filename,
fileOpenMode, FileAccess.Write, FileShare.Read);
                            m_append=true;
                        }
                    }
                    catch (Exception e1)
                    {
                        CurrentAppender.ErrorHandler.Error("Unable to
acquire lock on file "+m_filename+". "+e1.Message);
                    }
                }
                return m_stream;
            }


The benefit is that anyone who uses log4net will feel convenient

Reply via email to