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 Yuri Astrakhan <yu...@hotmail.com> on 2004/10/23 04:07:28 UTC

Implementing complex message logging objects

Hello,

I am trying to use log4net to store arbitrary complex data objects.
For example, i have sensor data that i would like to output to both
XML and database storage. I would like to implement it in the most
generalized way possible to be of use to others in the community.

Example:
class DataObject {
  string strData;
  int intData;
}

When logging to an XML file, the object should be outputted in a structured 
way:
<event logger="..." timestamp="..." ... >
  <message>
    <value name="StrData" value="meaning of life" />
    <value name="IntData" value="42" />
  </message>
</event>

When saving to database, some mapping has to be specified (similar to 
ADONetAppender's ADONetAppenderParameter).

I just recently started using log4net, and don't have much expertise
in it. Please advise on the better way to implement this.

My thoughts so far:
1. A new layout that can pull just one property out of the data object:
<param name="MessageProperty" type="log4net.Layout.DataObjectLayout">
  <param name="Property" value="StrData" />
</param>
For now, "Property" will only point to a immediate object property, but 
later it can be extended to complex objects:  <...value="DateBirthday.Year" 
/>

2. Two appenders that can take a list of MessageProperty parameters to
output in whichever way needed (ado or xml or plain text):

I am concerned with the efficiency of such solution, but this way it
follows established framework. It might be more efficient to implement an 
appender that uses reflection as appose to configuration settings to 
enumerate all message object's properties. But then layout architecture will 
not be used, and custom object renderings will not be possible.

Thanks!!!

--ya

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/