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
Von: Howe, Peter L [mailto:[email protected]]
Gesendet: Mittwoch, 24. Juli 2013 18:41
An: Log4NET Dev
Betreff: RE: File naming
This is interesting that you say it is not supported. My configuration
looks like this:
<appender name="DateSeparatedLogFileAppender"
type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString"
value="C:\temp\logs\%processid_" />
<staticLogFileName value="false"/>
<appendToFile value="true"/>
<rollingStyle value="Date"/>
<datePattern value="yyyyMMdd'_MyApplication.log'"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern"
value="%date [%-5thread] %-5level %-35username -
%message%newline%exception"/>
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG"/>
<levelMax value="FATAL"/>
</filter>
</appender>
And I am getting a separate file for each execution of the program:
3268-_20130724_MyApplication.log
5844-_20130724_MyApplication.log
10460-_20130724_MyApplication.log
I tried some tricks to get the date component first for easier sorting, but
no luck.
Peter
From: Dominik Psenner [mailto:[email protected]]
Sent: Wednesday, July 24, 2013 10:54 AM
To: 'Log4NET Dev'
Subject: AW: File naming
Hi,
try different configurations for each instance. Unfortunately currently
there's no way to configure the rolling file appender so that it encodes the
process id in the filename. Feel free to open an issue if the "multiple
configurations"-workaround is not a solution for you. Please consider also
when creating a new issue to link it with issue LOG4NET-367 so that
whoever's going to work on LOG4NET-367 will consider your usecase.
Cheers,
Dominik
Von: Howe, Peter L [mailto:[email protected]]
Gesendet: Mittwoch, 24. Juli 2013 16:17
An: Log4NET Dev
Betreff: File naming
HI,
I need a little help figuring out to write the app.config file syntax for
including the process ID in the file name. Our company needs to make sure
that multiple instances of the same app running on the server use separate
log files. We want a filename something like:
yyyymmdd_ProcessID_OurApplication.log
If anyone can help with the syntax, that would be great. I have looked
around the apache site at documentation and done some "trial and error"
testing, but so far only failures.
Thanks,
Peter
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.