You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by "Herrmann, David G" <da...@intel.com> on 2011/11/02 22:03:50 UTC

log4net advice

To: Someone more knowledgeable in log4net than myself.

I have just downloaded the 1.2.11 version of log4net. I am learning how to use it and can get basic logging done in my application. However, I have a need for something that I'm not sure how to do if it is possible at all.

I need to be able to log to different log files within the same application where I don't know the log file names in advance so I cannot create the necessary appenders in my app.config file before hand. I will only know the log file name at run time. Is there a way I can do this? Can I use one appender that is defined in my app.config file but substitute a different file name at run time somehow? Or is there a way to set up my logger using just the log4net API?

I see that log4net comes with an extensive API but if this is possible I don't see it in the API. If I can specify log file names at run time, how would I do that?

Thank you very much for any advice on this.

-Dave Herrmann


RE: log4net advice

Posted by Richard Pennenga <rp...@angel-med.com>.
David,

You could loop through all the Appenders, looking for the one with your specific name, and then change the appropriate property at runtime.

I found really useful code for looping through & finding Appenders from Andrew Andrew Elmhorst and Nicko Cadell, posted here:  http://www.l4ndash.com/Log4NetMailArchive%2Ftabid%2F70%2Fforumid%2F1%2Fpostid%2F15439%2Fview%2Ftopic%2FDefault.aspx

I had to tweak it a bit more for BufferingForwarding Appenders - but if your Appenders are hung off the root and are just rollingfile Appenders or something else with no indirection, you can probably use the simplest sample code.

If you need more help feel free to repost.

Richard J. Pennenga
Software Developer

Angel Medical Systems, Inc.
T:  732-542-5551 x110
F:  732-542-5560
rpennenga@angel-med.com
www.angel-med.com   [cid:image001.jpg@01CC998A.50776400] <http://twitter.com/AngelMedSystems>    [cid:image002.jpg@01CC998A.50776400] <http://www.youtube.com/AngelMedicalSystems>    [cid:image003.jpg@01CC998A.50776400] <http://www.facebook.com/home.php?#/pages/Shrewsbury-NJ/Angel-Medical-Systems/78938919935?ref=ts>    [cid:image004.jpg@01CC998A.50776400] <http://www.linkedin.com/companies/88422?trk=ape_s000001e_1000>