Ian,

The AdoNetAppender example simply shows logging fields that the
LoggingEvent captures for each event. You do not need to log the same
fields into that schema. The AdoNedAppender just calls a parameterised
stored procedure or prepared statement. The only requirement is that you
can pass your logging data in one or more parameters.

There are a number of different ways to log additional fields. The
LoggingEvent has a properties map that can be used to store arbitrary
named fields. These can be logged using the "%P{property name}" pattern.
If you have a consistent set of fields that you want to pass into
log4net then you may want to write a custom log4net extension so that
you can do this through a strongly typed interface. For an example see
the EventID extension in the log4net 1.2 beta8 download
(log4net-1.2.0-beta8\extensions\net\1.0\log4net.Ext.EventID\cs\src).
This extension allow you to pass in a long EventID which is then stored
in a property on the LoggingEvent.

Passing in a string of XML data raises additional concerns like ensuring
that the string is valid. If you want to pass in an XML string as the
message you can still crack the XML into its component parts and log
them as parameters to the AdoNetAppender. You will need to write a new
layout that cracks the XML string from the LoggingEvent and returns the
value for the field you are interested in. Each parameter to the
AdoNetAppender takes a separate layout so you could write a layout for
each field or just one layout you reuse and parameterise for each field.
Have a look at log4net.Layout.SimpleLayout in the log4net source for
details on how to implement a layout.

Cheers,
Nicko

> -----Original Message-----
> From: Ian Bell [mailto:[EMAIL PROTECTED] 
> Sent: 24 November 2004 16:59
> To: [email protected]
> Subject: Re: Custom Appender
> 
> 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