RE: How to add an Appender to Log4net programmati cally at runtime ?

Vincent Daron <[email protected]> Fri, 23 Jan 2004 10:36:44 +0100
Newsgroups gmane.comp.windows.dotnet.log4net.user
Message-ID <1074850604.2926.2.camel@localhost>
Thanks, it works !

log4net is wonderfull, really a great peace of software :)

See you

Vincent


Le ven 23/01/2004 =E0 01:49, Nicko Cadell a =E9crit :
> Vincent,
> =20
> I think what you want to do is only attach your appender to the root
> logger. By default this will be inherited by all your existing loggers
> as well as by newly created loggers. To do this you can write:
> =20
>=20
> ((log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetLoggerRe=
pository()).Root.AddAppender(your appender here);
>=20
> If you still are having problems can you also post the version of
> log4net and the configuration file that you are using.
>=20
> Thanks,
>=20
> Nicko
>=20
>=20
>         -----Original Message-----
>         From: Vincent Daron [mailto:[email protected]]=20
>         Sent: 22 January 2004 16:39
>         To: [email protected]
>         Cc: 'Denis, Rich'
>         Subject: RE: [Log4net-users] How to add an Appender to Log4net
>         programmatically at runtime ?
>        =20
>        =20
>        =20
>         But when a new Logger is created, it receive some appenders, I
>         just like to be include in this list ....
>        =20
>         =20
>        =20
>         I'll look into the code...
>        =20
>         =20
>        =20
>         Thanks
>        =20
>                                       =20
>         ______________________________________________________________
>        =20
>         From: Denis, Rich [mailto:[email protected]]=20
>         Sent: jeudi 22 janvier 2004 17:34
>         To: 'Vincent Daron'
>         Subject: RE: [Log4net-users] How to add an Appender to Log4net
>         programmatically at runtime ?
>        =20
>        =20
>         =20
>        =20
>         You make perfect sense.  Unfortunately I don't think that you
>         can do what you are trying to do.  You are only modifying the
>         loggers that are known at the time you run your code.  The
>         only way I could think that you would get it to work is to
>         somehow programmatically set the configuration file, but I am
>         not sure how you would do this.
>        =20
>         =20
>        =20
>         =20
>        =20
>         Rich Denis
>         perotsystems(tm)
>        =20
>         (972) 577-5869 Wk
>        =20
>         =20
>        =20
>        =20
>                                       =20
>         ______________________________________________________________
>        =20
>         From: Vincent Daron [mailto:[email protected]]=20
>         Sent: Thursday, January 22, 2004 10:23 AM
>         To: Denis, Rich
>         Subject: RE: [Log4net-users] How to add an Appender to Log4net
>         programmatically at runtime ?
>        =20
>        =20
>         =20
>        =20
>         Thanks, but it did'nt solve my problem ...
>        =20
>         =20
>        =20
>         I'll try to be clearer,
>        =20
>         =20
>        =20
>         I've created an Appender, and I want to "Attach" it on all the
>         Loggers at runtime. I want to Add it to the Appender specified
>         in configuration file. I've found the following code since my
>         first post :
>        =20
>         =20
>        =20
>         foreach(ILoggerRepository tmp in
>         LoggerManager.GetAllRepositories())
>        =20
>         {
>        =20
>            foreach(Logger tmp2 in tmp.GetCurrentLoggers())
>        =20
>            {
>        =20
>               tmp2.AddAppender(theAppender);
>        =20
>            }
>        =20
>         }
>        =20
>         =20
>        =20
>         The problem with this approach is that all the assemblies
>         loaded after this code do not log in My Appender (but they log
>         in the appenders specified in configuration). If I load these
>         assemblies before (by creating a dummy object for example), it
>         run fine, and MyAppender receive every LoggingEvent... I can't
>         do it for all the external assemblies of course ....
>        =20
>         =20
>        =20
>         Thanks for answer
>        =20
>         =20
>        =20
>         Sorry for my poor English ...
>        =20
>         =20
>        =20
>         Vincent
>        =20
>                                       =20
>         ______________________________________________________________
>        =20
>         From: Denis, Rich [mailto:[email protected]]=20
>         Sent: jeudi 22 janvier 2004 17:01
>         To: 'Vincent Daron'
>         Subject: RE: [Log4net-users] How to add an Appender to Log4net
>         programmatically at runtime ?
>        =20
>        =20
>         =20
>        =20
>         Try it without the MyAppender. i.e. =20
>        =20
>         =20
>        =20
>          log4net.Config.BasicConfigurator.Configure()
>        =20
>         =20
>        =20
>         Rich Denis
>         perotsystems(tm)
>        =20
>        =20
>                                       =20
>         ______________________________________________________________
>        =20
>         From: Vincent Daron [mailto:[email protected]]=20
>         Sent: Thursday, January 22, 2004 9:31 AM
>         To: [email protected]
>         Subject: [Log4net-users] How to add an Appender to Log4net
>         programmatically at runtime ?
>        =20
>        =20
>         =20
>        =20
>         Hi
>        =20
>         =20
>        =20
>         By using
>         log4net.Config.BasicConfigurator.Configure(MyAppender)
>        =20
>         it run pretty fine, but I lost all the log4net configuration
>         stored in the config file...
>        =20
>         =20
>        =20
>         Thanks for help
>        =20
>         =20
>        =20
>         Vincent
--=20
Vincent Daron
Analyst Programmer
ASK sa.



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn