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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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; how did you solve properties file problem. My program is still crashing while reading the properties files. See complete description of my problem at stackoverflow.com/questions/31029569/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.