views:

320

answers:

1

How do I implement a custom LOG4NET parser for my XML file. My XML file contains:
(1) extra attributes on the appender element
(2) custom replacements on the elements of some of the appenders that need to be set at runtime.

For example:

<appender name=... type=... mode="something">
<some-property-of-appender>${MyValueForThisPropertyFromDB}</some-property-of-appender>
</appender>

I have read that I am supposed to implement a Custom Repository probably using the LoggerRepositorySkeleton but not sure how to put this whole thing together. Any suggestions?

A: 

Since you are trying to initialize most of the log4net configuration from database the easiest way would be to configure log4net from code. Then you will have full control over what parameter values you use and where they come from.

Peter Lillevold
Thank you but am not really looking for an appender. I would have to change almost every appender that log4net has if I go down this route. Ideally I would like to intercept before the appender is created and change ALL the parameters by looking up the values in my database. Then I would like to pass what I have to log4net so it can continue initializing
Just to clarify the above. I think I need to somehow replace all the attributes and element values marked with ${some-key-to-lookup} in the log4net.config when it is being loaded by log4net before log4net intialized the appender. Then log4net should initialize the appender with my resolved values substituted and move on to the next appender and repeat.
Ah I see. I've revised my answer accordingly
Peter Lillevold
Thank you, Yeah, this is kind of the way I am going about it. To do most of this programmatically - just wondering if there is an easier way to do it. Just was hoping to learn how to do it using the LoggerRepositorySkeleton. Can't seem to find any examples of how to use LoggerRepositorySkeleton.