In log4net i can easily set process id to to log file name from config easily
<appender name="LogFileAppender"
type="log4net.Appender.RollingFileAppender,log4net">
<file type="log4net.Util.PatternString" value="Log[%processid]" />
- Can i do the same for the log4cxx from config file?
- If yes, how?
According to the log4cxx documentation in order to currently do this you need to declare at least one MappedDiagnostic context.
An untested partial snippet of doing so is shown below
After further inspection of the log4cxx source, I realised that file doesn't take a ConversionPattern but FileNamePattern does. I believe you can only use FileNamePattern when you have use a TimeBasedRollingPolicy or FixedWindowRollingPolicy.
Now you can add the processid to the log by adding the following parameter in your appender tags in the XML configuration file.
or you can include it in the pattern layout by specifying the following layout tags also inside your appender tags in the XML configuration file.
There is no simple way from the configuration file only to have each process append its own process to its own log like you are familiar with in log4net.
There were several log4cxx mailing list threads that mention dynamic log renaming, but all of them involved numerous changes in the C++ code and they don't do what you request.
The method they used involves having
<param name="file" value="${logfilename}"/>
where $logfilename is an environment variable that gets set bycalling something like the above snippet in the C++ code, each time you want the log name to change.
Other methods would involve patches to log4cxx as it currently doesn't have the functionality you need.
References
log4cxx Conversion Pattern Wiki
Short introduction to Apache log4cxx
log4cxx Tutorial
MDC log4cxx Class Reference