You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by "Ron Grabowski (JIRA)" <ji...@apache.org> on 2008/01/05 23:03:33 UTC

[jira] Commented: (LOG4NET-31) Allow user to pass in additional parameters to node via some kind of tag

    [ https://issues.apache.org/jira/browse/LOG4NET-31?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12556288#action_12556288 ] 

Ron Grabowski commented on LOG4NET-31:
--------------------------------------

I've implemented property support for PatternConverters so this syntax is supported:

<converter>
  <name value="user-converter" />
  <type value="Company.Project.Logging.UserConverter, Company.Project" />
  <property>
   <key value="address" />
   <value value="HomeAddress" />
  </property>
 </converter> 

Its easy to add property support to other objects like Appenders but those are more well-defined than converters (think plugins) and explicit properties should be used.

> Allow user to pass in additional parameters to <converter> node via some kind of <property> tag
> -----------------------------------------------------------------------------------------------
>
>                 Key: LOG4NET-31
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-31
>             Project: Log4net
>          Issue Type: Improvement
>            Reporter: Ron Grabowski
>            Assignee: Ron Grabowski
>            Priority: Minor
>
> It would be useful if the user was able to supply additional properties to the <convert> tag in the form of:
>  <property name="foo" value="bar" />
>  <property name="Hello" value="World" />
> The code below uses a <property> node to determine if the HomeAddress or the WorkAddress will appear in the log message. If the parameter is not present, the converter prints a default value.
>  <converter>
>   <name value="user-converter" />
>   <type value="Company.Project.Logging.UserConverter, Company.Project" />
>   <property name="Address" value="HomeAddress" />
>  </converter>
>  <conversionPattern value="%p %d %user-converter{Nicko} - %m%n" />
> The <property> tags would be accessible via a Properties IDictionary. It would allow the converter to perform additional logic on the base.Option that was passed in:
>  public class MyConverter : PatternConverter
>  {
>   override protected void Convert(TextWriter writer, object state) 
>   {
>    User user = GetUserByUserName(base.Option);
>    string address = base.Properties["Address"] as string;
>    if (address != null && address.Length > 0)
>    {
>     if (user != null)
>     {
>      switch (address)
>      {
>       case "HomeAddress": writer.Write(user.HomeAddress); break;
>       case "WorkAddress": writer.Write(user.WorkdAddress); break;
>      }
>     }
>     else
>     {
>      // ???
>     }
>    }
>    else
>    {
>     // default display
>     writer.Write(user.HomeAddress); break;   
>    }
>   }
>  }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.