logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From T Dog <acedog032...@yahoo.com>
Subject RE: how often to call XmlConfigurator.Configure
Date Fri, 03 Sep 2010 16:16:03 GMT
log4net has been a great benefit to me since I have been using it, so thank you for working
on it.  I really want to understand it better.  Are there any examples of using it so that
each class has its own appender?  This could be useful in some cases.

Thanks again.

--- On Fri, 9/3/10, Radovan Raszka <raszka@hasam.cz> wrote:

> From: Radovan Raszka <raszka@hasam.cz>
> Subject: RE: how often to call XmlConfigurator.Configure
> To: "Log4NET User" <log4net-user@logging.apache.org>
> Date: Friday, September 3, 2010, 4:20 AM
> 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:acedog032000@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();
> 
> 
> 
> 
> 
>       
> 
> 


      


Mime
View raw message