|
[
Permlink
| « Hide
]
Ron Grabowski added a comment - 06/Nov/05 07:18 AM
Added WriteDictionary overload that accepts an IDictionaryEnumerator
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 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); 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.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||