[
http://issues.apache.org/jira/browse/LOG4NET-31?page=comments#action_65850 ]
Nicko Cadell commented on LOG4NET-31:
-------------------------------------
The 'log4net:ERROR XmlHierarchyConfigurator: Cannot find Property [address] to
set object on [log4net.Layout.PatternLayout+ConverterInfo]' error is expected
because the XmlHierarchyConfigurator uses reflection to set the values of
properties on objects using the XML as a source.
There are a couple of ways of achieving your example with the current
implementation. First you could write 2 converters, one for the HomeAddress and
one for the WorkAddress, then select which one to use in the config file.
Alternatively you could write 1 converter which parses the Home/Work tag from
the start of the Option string, i.e. you would write in the pattern
%user-converter{Home:Ron}. The converter could split the Option string on the
colon to decide what to do.
These workarounds are not as generalised as what you are suggesting.
> Allow user to pass in additional parameters to <converter> node via some kind
> of <property> tag
> -----------------------------------------------------------------------------------------------
>
> Key: LOG4NET-31
> URL: http://issues.apache.org/jira/browse/LOG4NET-31
> Project: Log4net
> Type: Improvement
> Reporter: 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.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira