Log4net
  1. Log4net
  2. LOG4NET-30

Add support for type aliases in config file

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Trivial Trivial
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 1.2 Maintenance Release
    • Component/s: None
    • Labels:
      None

      Description

      IBatisNet uses "type" attributes in their xml config files:

      type="Company.Project.Foo.Data.Entity.Product, Company.Project.Data"
      type="Company.Project.Foo.Data.Entity.Category, Company.Project.Data"
      type="Company.Project.Foo.Data.Entity.User, Company.Project.Data"

      to save the user from having to re-type long strings every time something references a Product, Category, etc. They define an <alias> node that contains <typeAlias> entries:

      <alias>
      <typeAlias alias="Product" type="Company.Project.Foo.Data.Entity.Product, Company.Project.Data" />
      <typeAlias alias="Category" type="Company.Project.Foo.Data.Entity.Product, Company.Project.Data" />
      <typeAlias alias="User" type="Company.Project.Foo.Data.Entity.Product, Company.Project.Data" />
      </alias>

      Wherever I have to specify a type, I may use one of the aliases I defined at the top of the file.

      It would be nice if log4net supported a similiar concept. It would also be nice if log4net shipped with some default aliases. I think normal casing would be ok:

      FileAppender -> log4net.Appender.FileAppender

      An example incorporating the above suggestions would be (this will probably wrap when it posts to the mailing list):

      <alias>
      <typeAlias alias="SessionContextPatternConverter" type="log4netAspExtensions.SessionContextPatternConverter, log4netAspExtensions" />
      <typeAlias alias="CacheContextPatternConverter" type="log4netAspExtensions.CacheContextPatternConverter, log4netAspExtensions" />
      <typeAlias alias="RequestContextPatternConverter" type="log4netAspExtensions.RequestContextPatternConverter, log4netAspExtensions" />
      <typeAlias alias="ApplicationContextPatternConverter" type="log4netAspExtensions.ApplicationContextPatternConverter, log4netAspExtensions" />
      </alias>

      <appender name="LoginFileAppender" type="FileAppender">
      <file value="c:/inetpub/wwwroot/Logs/Logins.txt" />
      <layout type="PatternLayout">
      <converter>
      <name value="asp-session" />
      <type value="SessionContextPatternConverter" />
      </converter>
      <conversionPattern value="%5p %d (%c:%L) - [%asp-session

      {UserId}] %m%n" />
      </layout>
      </appender>

      I haven't fully looked into the <convertor> node to see if it can support this style of attributes but an even shorted syntax might be:

      <appender name="LoginFileAppender" type="FileAppender">
      <file value="c:/inetpub/wwwroot/Logs/Logins.txt" />
      <layout type="PatternLayout">
      <converter name="asp-session" type="SessionContextPatternConverter" />
      <conversionPattern value="%5p %d (%c:%L) - [%asp-session{UserId}

      ] %m%n" />
      </layout>
      </appender>

      It should be possible to overwrite the builtin aliases. Had I overridden FileAppender:

      <typeAlias alias="FileAppender" type="log4netAspExtensions.AspNetFileAppender, log4netAspExtensions" />

      I would be able to declare my appender with support for the ~ character:

      <appender name="LoginFileAppender" type="FileAppender">
      <file value="~/Logs/Login.txt" />
      <layout type="PatternLayout">
      <converter name="asp-session" type="SessionContextPatternConverter" />
      <conversionPattern value="%5p %d (%c:%L) - [%asp-session

      {UserId}

      ] %m%n" />
      </layout>
      </appender>

      I think that the above changes would descrease the size of the config file and increase the files readability.

        Activity

          People

          • Assignee:
            Unassigned
            Reporter:
            Ron Grabowski
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development