Hi Patrick,

You can do the same thing easier with log4cxx using environment variables. 
Before initializing log4cxx, put your special folders into environment 
variables:
       char theDirectory[256];
       char envVar[280];
       ....determine application data dir....
       sprintf(envVar, "CommonApplicationData=%ld", theDirectory);
       _putenv(envVar);

then in your configuration file:
 <appender name="RFA" class="org.apache.log4j.rolling.RollingFileAppender">
   <rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
     <param name="activeFileName" value="${CommonApplicationData}\mcli.log"/>
     <param name="fileNamePattern" 
value="${CommonApplicationData}\mcli.log.%i"/>
     <param name="minIndex" value="0"/>
     <param name="maxIndex" value="5"/>
   </rollingPolicy>
   <triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
     <param name="MaxFileSize" value="30MB"/>
   </triggeringPolicy>
   <layout class="org.apache.log4j.PatternLayout">
     <param name="ConversionPattern" value="%d{MM/dd HH:mm:ss.SSS} %c - %m%n"/>
   </layout>
   <param name="file" value="${CommonApplicationData}\mcli.log"/>
   <param name="append" value="false"/>
 </appender>

-Andy


Patrick Lannigan wrote:

Curt Arnold wrote:


    On Apr 11, 2008, at 1:28 PM, Patrick Lannigan wrote:
    > In a project that uses log4net, I have successfully added the
    > pattern demonstrated to access Windows Special folders
    > 
http://mail-archives.apache.org/mod_mbox/logging-log4net-user/200506.mbox/[EMAIL
 PROTECTED]
    >
    > I am now trying to do the same with log4cxx, but seem to be running
    > into some roadblocks. Is it possible to produce this same result in
    > log4cxx? If so, can an example be given to show how the log4cxx
    > version would differ from log4net?

    Could you explain your use case? The most obvious one to me is to be
    able to use a folder path in a configuration file to specify the
    location of a log file, but that isn't consistent with the log4net
    example. The location of special folders should not change during a
    run, so I don't see the value in adding it as a converter for the
    pattern layout. It would just be simpler to output the value of the
    special folders as INFO logging requests at the start of the run
    instead of evaluating them over and over during the layout of messages.

I am using it to set the path to a log file. I need to place the log file in 
the common app data folder, which can be different for each machine and is only 
known at runtime. So I used the following in my log4net config file.

      <file type="log4net.Util.PatternString">
        <converter>
          <name value="folder" />
          <type value="log4net.SpecialFolderPatternConverter,MCLI" />
        </converter>
        <converter>
          <name value="subdir" />
          <type value="log4net.ProductSubDirectoryPatternConverter,MCLI" />
        </converter>
        <conversionPattern 
value="%folder{CommonApplicationData}\%subdir\mcli.log" />
      </file>

I am trying to achieve this same functionality with the log4cxx config file. I 
have also found that specifying a file name without a path creates a file in 
the base directory. This means in order to write to the correct folder I would 
have to write my own functions to create the appender and build a file name 
based on what the calling process is. This limits the runtime configurability 
to just log levels and we would need a new binary in order to change what 
information is printed for each log message.

Reply via email to