Search code examples
c++visual-studiolog4cxx

Could not open file [TESTXML.xml]


I am using Visual Studio 2015.

Currently I am working on a wrapper for log4cxx so that any other logging library can be used later down the line.

I am using DOMConfigurator to parse an XML configuration file. Basically my function wraps DOMConfigurator::configure().

I pass it a literal string, which is the name of my configuration file, in this case, "TESTXML.xml", however, I receive the message on my console that:

log4cxx: Could not open file [TESTXML.xml].

I have also tried passing it a string variable, to no avail.

Why can't I open the file? I have added my file under "Source Files" and modified the properties:

  • Content: Yes
  • Excluded From Build: No

Perhaps there is a setting in MSVS2015 I am forgetting to configure?


Solution

  • Perhaps there is a setting in MSVS2015 I am forgetting to configure?

    No, it doesn't have to do with the configuration of that file (which should be excluded from the build BTW).

    With the information given in your question, the most probable reason that opening the configuration XML file fails is that it's not located in the same directory where your process is started.

    Visual Studio will run the executable in the same directory as it was created by default (i.e. $(ProjectDir)/<target>/Debug or $(ProjectDir)/<target>/Release).

    You can modify the process working directory in the project properties debug settings, or open a cmd window, change to the desired working directory and start your executable manually.

    Another option is to set the full path filename for the configuration file (e.g. "c:\user\xyz\MySolution\MyProject\TESTXML.xml"). Remember that for C++ string literals, you need to escape the backslash characters (\ ==> \\), unless you are using a raw string literal.