Issue Details (XML | Word | Printable)

Key: LOG4NET-56
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Nicko Cadell
Reporter: Ron Grabowski
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Log4net

Support rendering IEnumerator objects as well as ICollections

Created: 06/Nov/05 07:14 AM   Updated: 03/Mar/06 12:55 AM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2.10

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works WriteDictionaryUsingIDictionaryEnumerator.patch 2005-11-06 07:18 AM Ron Grabowski 2 kB

Resolution Date: 03/Mar/06 12:55 AM


 Description  « Hide
Some objects that use IDictionary objects expose an IDictionaryEnumerator instead of the underlying IDictionary. HttpRuntime.Cache.GetEnumerator() is one such object.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Ron Grabowski added a comment - 06/Nov/05 07:18 AM
Added WriteDictionary overload that accepts an IDictionaryEnumerator

Ron Grabowski added a comment - 06/Nov/05 08:18 AM
I think something else needs to be changed further up in the chain to allow these two statements to produce the same output:

 Hashtable hashTable = new Hashtable()
 hashTable["Hello"] = "World";

 // OK
 log.Debug(hashTable);

 // prints out GetType().ToString()
 log.Debug(hashTable.GetEnumerator()); // GetEnumerator returns IDictionaryEnumerator

Nicko Cadell added a comment - 13/Nov/05 06:11 AM

The PatternConverter is the base class for the converters used by the PatternLayout and the PatternString. The WriteDictionary helper method in the base probably does not need extra support for the IDictionaryEnumerator as it is only used to render IDictionary objects.

A call like:
log.Debug(hashTable);

will use the ObjectRenderer to convert the ICollection into a string. The code that does this conversion is in log4net.ObjectRenderer.DefaultRenderer.

The reason why a call like:

log.Debug(hashTable.GetEnumerator());

does not produce the same output is that the log4net.ObjectRenderer.DefaultRenderer code does not know how to render objects of type IEnumerator.

The HttpRuntime.Cache object (of type System.Web.Caching.Cache) is a dictionary, but it does not implement the IDictionary interface, nor does it implement ICollection. It does implement the IEnumerable interface.

If you just change the log4net.ObjectRenderer.DefaultRenderer so that instead of checking for ICollection it checks for IEnumerable then you can call:

log.Debug(HttpRuntime.Cache);

Nicko Cadell added a comment - 03/Mar/06 12:55 AM
Added support for rendering all IEnumerable types and IEnumerators rather than just collections. Added spacial case for IDictionary to ensure that the enumerator returned will enumerate DisctionaryEntry objects even with .NET 2.0 generic collections.