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: Reporting events back to Unit-test
Date Wed, 08 Dec 2004 19:05:47 GMT
In the unit test you could add a MemoryAppender and then at the end of
the operation query it for events that have been logged.

log4net.Appender.MemoryAppender mem = new
log4net.Appender.MemoryAppender();
mem.Name = "MemoryAppender";
mem.ActivateOptions();

log4net.Repository.Hierarchy.Hierarchy h =
(log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetLoggerRepo
sitory();
h.Root.AddAppender(mem);

// Do stuff that logs

h.Root.RemoveAppender(mem);
LoggingEvent[] events = mem.GetEvents();
mem.Clear(); 

// Inspect events logged


Nicko

> -----Original Message-----
> From: Andrew Elmhorst [mailto:nospam@elmhorst.com] 
> Sent: 08 December 2004 14:58
> To: 'Log4NET User'
> Subject: RE: Reporting events back to Unit-test
> 
> Log4net comes with MemoryAppender that stores all logged 
> event in memory.
> This would be useful for a Unit Test, as it can check the 
> Events property and get back an array of all the 
> LoggingEvents that have been logged.
> 
> Regards,
> 
> Andrew Elmhorst
> 
> -----Original Message-----
> From: Olav Benum [mailto:olavagfa@hotmail.com]
> Sent: Wednesday, December 08, 2004 8:13 AM
> To: log4net-user@logging.apache.org
> Subject: Reporting events back to Unit-test
> 
> Hi
> 
> I am using NUnit and log4net, and I would like to use log4net 
> to report certain events back to the unit test.
> 
> What would be the best way to do this?
> 
> It seems I can't generate events and attach to them?
> 
> It should be possible to inspect to obtain the relevant 
> logger, and inspect it at regular intervals.
> 
> Also I need to make sure (from unit test at run-time) that 
> what I look for is really logged.
> 
> One situation where I need this is when I want to test an 
> unavailable connection.  This is logged anyway, and as the 
> unit-test don't know the assembly directly, it would be 
> easiest to communicate through the logging-framework.
> 
> Thanks
> Olav
> 
> _________________________________________________________________
> Free mail? MSN Hotmail ! http://www.msn.be/hotmail
> 
> 
> 
> 

Mime
View raw message