Common.Logging and Log4Net.xml file not found issue

chenyuhao88 used Ask the Experts™
Dear All,

I am using Common.Logging to do the logging function. I have a windows application, which runs ok to log. The code is as simple as:

            NameValueCollection properties = new NameValueCollection();
            properties["configType"] = "FILE-WATCH";
            properties["configFile"] = "./Log4Net.xml";

            LogManager.Adapter = new Log4NetLoggerFactoryAdapter(properties);
            ILog log = LogManager.GetCurrentClassLogger();


I think as long as that "Log4Net.xml" is under bin or bin/debug folder, it is fine.

However I also created another windows service project which will call the methods in my previous application. But this time when it goes to:

LogManager.Adapter = new Log4NetLoggerFactoryAdapter(properties);

It says "file Log4Net.xml os not found". Actually I have put that configuration file under the bin/debug folder of both 2 projects, but it still reports error.

Does anyone know actually which directory it is looking at when my windows service calling that method?

Thanks heaps!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I guess that you need to get working directory of windows services, using statement

dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

 properties["configFile"] = dir+"/Log4Net.xml";


Thanks Trungk43!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial