Thanks for that - I was thinking along the lines of pass my XML in as the
message. The only problem with that was the fact that it didn't seem to fit
in with the config 'philosophy' of log4net. I'd had hoped that I could
somehow create my own LoggingEvent to pass in, and then change my app.config
thus:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

        <configSections>
                <section name="log4net"
type="System.Configuration.IgnoreSectionHandler" />
        </configSections>

<appSettings>
<add key="log4net.Internal.Debug" value="true" /> </appSettings>

<log4net>


        
        
        <appender name="ADONetAppender_SqlServer"
type="log4net.Appender.ADONetAppender" >
           <param name="ConnectionType"
value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" />
           <param name="ConnectionString" value="data source=(local);initial
catalog=hbos;integrated security=false;persist security info=True;User
ID=xxx;Password=xxx" />
           <param name="CommandText" value="up_HBOSLogMessage" />

           <param name="Parameter">
             <param name="ParameterName" value="@LogGUID" />
             <param name="DbType" value="String" />
             <param name="Size" value="36" />
             <param name="Layout" type="log4net.Layout.PatternLayout">
               <param name="ConversionPattern" value="%m" />
             </param>
           </param>
           
                   <param name="Parameter">
             <param name="ParameterName" value="@LogSecondaryId" />
             <param name="DbType" value="String" />
             <param name="Size" value="50" />
             <param name="Layout" type="log4net.Layout.PatternLayout">
               <param name="ConversionPattern" value="%m" />
             </param>
           </param>
           
                   <param name="Parameter">
             <param name="ParameterName" value="@LogMessage" />
             <param name="DbType" value="String" />
             <param name="Size" value="40000" />
             <param name="Layout" type="log4net.Layout.PatternLayout">
               <param name="ConversionPattern" value="%m" />
             </param>
           </param>
           
                   <param name="Parameter">
             <param name="ParameterName" value="@LogType" />
             <param name="DbType" value="String" />
             <param name="Size" value="1" />
             <param name="Layout" type="log4net.Layout.PatternLayout">
               <param name="ConversionPattern" value="%m" />
             </param>
           </param>
           
                   <param name="Parameter">
             <param name="ParameterName" value="@LogPlatform" />
             <param name="DbType" value="String" />
             <param name="Size" value="50" />
             <param name="Layout" type="log4net.Layout.PatternLayout">
               <param name="ConversionPattern" value="%m" />
             </param>
           </param>
           
                   <param name="Parameter">
             <param name="ParameterName" value="@LogBranchCode" />
             <param name="DbType" value="String" />
             <param name="Size" value="6" />
             <param name="Layout" type="log4net.Layout.PatternLayout">
               <param name="ConversionPattern" value="%m" />
             </param>
           </param>
           
                   <param name="Parameter">
             <param name="ParameterName" value="@LogUserId" />
             <param name="DbType" value="String" />
             <param name="Size" value="10" />
             <param name="Layout" type="log4net.Layout.PatternLayout">
               <param name="ConversionPattern" value="%m" />
             </param>
           </param>
           
                   <param name="Parameter">
             <param name="ParameterName" value="@LogApplicationId" />
             <param name="DbType" value="String" />
             <param name="Size" value="255" />
             <param name="Layout" type="log4net.Layout.PatternLayout">
               <param name="ConversionPattern" value="%m" />
             </param>
           </param>
           
                           <param name="Parameter">
             <param name="ParameterName" value="@LogMachineId" />
             <param name="DbType" value="String" />
             <param name="Size" value="10" />
             <param name="Layout" type="log4net.Layout.PatternLayout">
               <param name="ConversionPattern" value="%m" />
             </param>
           </param>
           
                   <param name="Parameter">
             <param name="ParameterName" value="@LogMessageSwitchName" />
             <param name="DbType" value="String" />
             <param name="Size" value="44" />
             <param name="Layout" type="log4net.Layout.PatternLayout">
               <param name="ConversionPattern" value="%m" />
             </param>
           </param>
           
                   <param name="Parameter">
             <param name="ParameterName" value="@LogFreeFormText" />
             <param name="DbType" value="String" />
             <param name="Size" value="255" />
             <param name="Layout" type="log4net.Layout.PatternLayout">
               <param name="ConversionPattern" value="%m" />
             </param>
           </param>

        <root>
                <level value="DEBUG" />
                <appender-ref ref="ADONetAppender_SqlServer" />
        </root>
        
</log4net>

</configuration>


I intended to call the logger thus: Log.Debug(<my xml string>), where the
xml string would contain my xml data - of course this would also mean I'd
have to roll my own LoggingEvent class and also do something with Logger.cs
(to create an instance of my new EventLogger). This all seemed a little
complicated, but the docs do say that the EventLogger class can be extended
etc... Does this seem reasonable?

Good point about intercepting the message object in the Append method - I'll
look into that, but how do I reconcile the fact that I'm not interested in
logging any of the data the example schema describes, that I have my own
database schema. Any ideas? Because if I do intercept the message object and
extract/store the data therein, there's still the issue of the extra fields
(thead, level, logger etc) that comes as part of the sample ADO appender. 

Blimey, sorry to go on and on!

Yes, any example code would be great - please pass it on, and many thanks
for your email

Regards

Ian






-----Original Message-----
From: Simon Wallis [mailto:[EMAIL PROTECTED]
Sent: 22 November 2004 18:26
To: [email protected]; [EMAIL PROTECTED]
Subject: Re: Custom Appender

Hi Ian,

No, you don't need to do anything to the LoggingEvent class. You create your
own appender and override the Append(LoggingEvent loggingEvent) method. In
this function you can access loggingEvent.MessageObject, which will give you
the message you logged from your code -- in your case, an XML message. At
this point you have your XML and you can do whatever you want with it.

What type of data do you want to "pass in"? Do you mean to pass in as your
custom appender configuration, or pass in when you call log.Debug(...), etc?

If you need an example of a custom appender with custom config attributes
let me know, but it sounds like you're almost there.

Simon.


---------- Original Message ----------------------------------
From: "ian" <[EMAIL PROTECTED]>
Reply-To: <[EMAIL PROTECTED]>
Date:  Mon, 22 Nov 2004 10:38:59 -0500

>Hi
>
>I need to send in XML data which I then break up and store in a database -
any ideas as to the best way to do this? 
>
>I'm looking to create a custom appender, similar to the current ADONet
appender by extending the AppenderSkeleton class, and implementing the
Append method. 
>
>The trouble is, I'm a little confused when it comes to the LoggingEvent
class - am I right in thinking that I'll have to create my own LoggingEvent
class to define the data I want to pass in? If so, then I guess I'll also
have to override CallAppender in the Logger class to create my new
loggingevent object. 
>
>Am I on the right track with this line of thought? 
>
>Thanks in advance
>
>Ian
>


Reply via email to