Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-56

Support rendering IEnumerator objects as well as ICollections

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2.10
    • Component/s: None
    • Labels:
      None

      Description

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

        Activity

        Hide
        ron Ron Grabowski added a comment -

        Added WriteDictionary overload that accepts an IDictionaryEnumerator

        Show
        ron Ron Grabowski added a comment - Added WriteDictionary overload that accepts an IDictionaryEnumerator
        Hide
        ron Ron Grabowski added a comment -

        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

        Show
        ron Ron Grabowski added a comment - 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
        Hide
        nicko Nicko Cadell added a comment -

        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);

        Show
        nicko Nicko Cadell added a comment - 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);
        Hide
        nicko Nicko Cadell added a comment -

        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.

        Show
        nicko Nicko Cadell added a comment - 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.

          People

          • Assignee:
            nicko Nicko Cadell
            Reporter:
            ron Ron Grabowski
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development