You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Kevin Parkinson <de...@gmail.com> on 2007/07/19 00:00:40 UTC

ADONetAppenderParameter: Accessing Properties

Hello:

     I am trying to figure out how to set the AdpNetAppenderParameter
values in the log4net.config file to use properties of a class
inherited from LoggingEvent.

So, I understand that be default, setting up a parameter in the config
can look like this:

  <parameter>
    <parameterName value="@message" />
    <dbType value="String" />
    <size value="4000" />
    <layout type="log4net.Layout.PatternLayout" value="%message" />
  </parameter>

...this assigns the value of %message ( which I believe comes from the
logging event itself ) to the parameter named @message....understood!

Or, I could do this:

  <parameter>
    <parameterName value="@message" />
    <dbType value="String" />
    <size value="4000" />
    <layout type="log4net.Layout.PatternLayout" value="%property{myProperty}" />
  </parameter>

..this sets the value of the parameter @message to whateveer the value
is of 'myProperty', which I have perhaps set in the following way:

loggingEvent.Properties["myProperty"] = "foo";

...also, understood!

What I would really like to do is:

  <parameter>
    <parameterName value="@someDatabaseField" />
    <dbType value="String" />
    <size value="4000" />
    <layout type="log4net.Layout.PatternLayout"
value="MyDerivedLoggingEvent.PropertyOne" />
  </parameter>

...which really is the ability to set an AdoNetAppenderParameter's
value to some value on an instance of some class.

Does anyone have any ideas how to accomplish this? For example, should
I create my own derived AdoNetAppenderParameter, or am I limited to
the default method and expose all of the properties I want available
using the following code:

derivedLoggingEvent.Properties["PropertyOne"] = PropertyOne;

...and then...

<layout type="log4net.Layout.PatternLayout" value="%property{PropertyOne}" />

...I am not most fond of this method as it is not very dynamic.

discuss


-- 
Kevin Parkinson
Musician / Software Developer
Edmonton Alberta Canada