Log4net system should be configured only once int the "starting"  class of your 
application (first class used in the application) or any other class but before 
first logging attempt..
If you configure more times, only the last configuration is used.
But you can use log4net in way that every class uses its own appender.
RR

-----Původní zpráva-----
Od: T Dog [mailto:acedog032...@yahoo.com] 
Odesláno: 2. září 2010 19:16
Komu: log4net-user@logging.apache.org
Předmět: how often to call XmlConfigurator.Configure

I have a simple C# .net 2.0 program where a console application calls into a 
Caller class which then calls into a Callee class.  I want to have separate 
log4net configurations for the console application, for the Caller dll, and for 
the Callee dll.  Each of the 3 should write to its own rolling log file 
appender.   I call XmlConfigurator.Configure in the constructor of the Caller, 
the Callee, and in the Main method of the console application.  It ends up that 
the console application starts writing to its own log file, but then ends up 
writing into the innermost, the Callee's, log file.  I can get the console 
application to write back to its own log file if I call 
XmlConfigurator.Configure again before I want to write to the console app's log 
file.  Is that necessary or did I configure this incorrectly?  I want to be 
able to have varying levels of log4net capability and verbosity at each of the 
3 levels.

Here's the guts of the console application:

                log4net.Config.XmlConfigurator.Configure(new 
System.IO.FileInfo(Assembly.GetExecutingAssembly().Location + ".config"));

                string message = "message from main generated at : " + 
DateTime.Now.ToLongTimeString();
                _log.Error("error" + message);
                _log.Warn("warn" + message);
                _log.Info("info" + message);
                _log.Debug("debug" + message);
                
                Caller caller = new Caller();
                caller.MethodOne();

                // if the following line is commented out, then the output goes 
into the Callee's log file (which was the last class to call 
XmlConfigurator.Configure), not into the console application's log file
                log4net.Config.XmlConfigurator.Configure(new 
System.IO.FileInfo(Assembly.GetExecutingAssembly().Location + ".config"));
                message = "message from main generated at : " + 
DateTime.Now.ToLongTimeString();
                _log.Error("error" + message);
                _log.Warn("warn" + message);
                _log.Info("info" + message);
                _log.Debug("debug" + message);

                Caller caller2 = new Caller();
                caller2.MethodOne();





      

Reply via email to