logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: Best Method For Temporary Appender
Date Sun, 28 May 2006 23:53:00 GMT
Jon, 

> 1. How would my startup screen class obtain a reference to 
> the MemoryAppender such that it could read the logged events 

You can create the MemoryAppender programmatically and attach it by
calling:

((log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepositor
y()).Root.AddAppender(xxx)

Then you would have the reference to the appender.

Or you can configure the appender via one of the configurators and
locate it at runtime using:

log4net.LogManager.GetRepository().GetAppenders();


> 2. After startup completes and I no longer need the 
> MemoryAppender, is there a standard way of cleaning up or 
> would I just call the "Close" method on the MemoryAppender 
> reference. What are the consequences of removing an Appender 
> during runtime? 

You should call the RemoveAppender method on the relevant logger before
calling Close on the appender itself.

((log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepositor
y()).Root.RemoveAppender(xxx)


Cheers,
Nicko

Mime
View raw message