1. Log4net
  2. LOG4NET-30

Add support for type aliases in config file


    • 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:


      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:

      <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" />

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

      <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" />

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

      {UserId}] %m%n" />

      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" />

      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


      ] %m%n" />

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


        No work has yet been logged on this issue.


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


            • Created: