logging-log4net-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Howe, Peter L" <ph...@paychex.com>
Subject RE: File naming
Date Fri, 26 Jul 2013 13:38:08 GMT

I'm almost there, but I don't know enough about the code to see if it would roll properly.
 With this configuration:

     <file type="log4net.Util.PatternString"
           value="C:\temp\logs\%date{yyyyMMdd}_%processid_" />

      <staticLogFileName value="false"/>
      <appendToFile value="true"/>
      <rollingStyle value="Date"/>

      <datePattern value="dd'_MyApplication.log'"/>

I get files that are named like:

20130726_6600_26_MyApplication.log
20130726_6744_26_MyApplication.log
etc.

I had to leave the "dd" in the datePattern so it had something to roll on, but I have not
tried running the test application overnight to see what really happens at midnight...

Peter





From: Dominik Psenner [mailto:dpsenner@gmail.com]
Sent: Thursday, July 25, 2013 2:23 AM
To: 'Log4NET Dev'
Subject: AW: File naming

You found a workaround. Interesting. :) However, you won't get the date as a prefix for %processid.
I'm posting the code responsible for calculating the filename in the RollingFileAppender which
should explain why what's the case:

--- QUOTE ---
protected string GetNextOutputFileName(string fileName)
{
                if (!m_staticLogFileName)
                {
                               fileName = fileName.Trim();
                               if (m_rollDate)
                               {
fileName = CombinePath(fileName, m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo));
                               }

                               if (m_countDirection >= 0)
                               {
fileName = CombinePath(fileName, "." + m_curSizeRollBackups);
                                }
                }
                return fileName;
}
--- /QUOTE ---

where CombinePath behaves like this:

--- QUOTE ---
        private string CombinePath(string path1, string path2)
        {
            string extension = Path.GetExtension(path1);
            if (m_preserveLogFileNameExtension && extension.Length > 0)
            {
                return Path.Combine(Path.GetDirectoryName(path1), Path.GetFileNameWithoutExtension(path1)
+ path2 + extension);
            }
            else
            {
                return path1 + path2;
            }
        }
--- /QUOTE ---

Therefore there are various restrictions involved with how and where the date can be put into
the filename.

Currently there's no way of changing this since any way to improve this would require to change
the public API (the way the RFA is configured) and thus we will try to fix that filename trouble
once and for all with the rewrite of the RollingFileAppender. I can imagine that there won't
be a <datePattern> configuration anymore, but everything will be put into the <file>
tag where one will be able to use something like %date{format}. At least that's what I believe
would be the best since that allows people to put the date portion into directory names which
was often requested but so far has been impossible to do. And that way we allow even fancier
stuff to happen in the <file> tag. :) Even though this will complicate the rolling significantly
and there are a lot of cases that need to be taken care of.

Cheers

The information contained in this message may be privileged, confidential and protected from
disclosure. If the reader of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended recipient, you are hereby notified
that any dissemination, distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify your representative immediately
and delete this message from your computer. Thank you.

Mime
View raw message