1

I have downloaded Log4Cpp code project and built succesfully on my windows 7 64 bit machine. I have also used properties file in my code in following way -

const char* initFileName = "log4cpp.property";
   log4cpp::PropertyConfigurator::configure(initFileName);

I am using it in a console application so I placed log4cpp.property file in a bin directory where my exe file exist.

But whenever I am trying run 2nd line of code throws exception as given file does not exist. So can some body please help me with directory structure I should follow to use Log4Cpp

Thanks

user987316
  • 894
  • 4
  • 13
  • 35

1 Answers1

3

It can't be in the same directory as the executable file is in, it has to be in the programs current directory, which may or may not be the directory the executable is in.

For example, if you're in the director /home/foo/bar, and run a program in /home/foo/bin/, the current directory is where you are and not where the program is. In the case of this example the /home/foo/bar directory.

You can use e.g. getcwd (_getcwd on Windows) to get the programs current directory.

If your program will always be in the same place, you can use a full path to the property file.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Thanks Joachim it did solved my issue with properties file. I ahve another question can I create new log file each time using log4cpp. It is similar to Log4net which generates new log file in each app run and backs up old file with extension .1 .2. etc... . Any thoughts?? – user987316 Nov 11 '13 at 12:21
  • @user987316; how did you solve properties file problem. My program is still crashing while reading the properties files. See complete description of my problem at http://stackoverflow.com/questions/31029569/log4cpp-crashing-while-loading-properties-file – Tariq Jun 24 '15 at 16:32