Btw, you then need to pass the parameter to your stored procedure 
(@message). Based on what you have sent the following might work for you:

Note: I have just modified the example at 
http://logging.apache.org/log4net/release/config-examples.html#HC-12590745 
to suit your need.

<appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
                 <bufferSize value="<your buffer size>" />
                 <connectionType 
value="System.Data.SqlClient.SqlConnection, System.Data, 
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
                 <connectionString value="data source=[database 
server];initial catalog=[database name];integrated security=false;persist 
security info=True;User ID=[user];Password=[password]" />
                 <commandText value="<Your Stored Procedure Name>" />
                 <commandType value="StoredProcedure" />
                 <parameter>
                                 <parameterName value="@message" />
                                 <dbType value="String" />
                                 <size value="4000" />
                                 <layout 
type="log4net.Layout.PatternLayout">
                                                 <conversionPattern 
value="%message" />
                                 </layout>
                 </parameter>
</appender>

And if I might suggest, (unless you are testing out the functionality when 
you wrote the stored proc.. then ignore this) dont do a getDate() in the 
stored procedure, if there is a chance that you might get messages from 
multiple servers and/or their system time might be out of sync with the 
time on your application server. You will be better off by changing it to 
another stored proc parameter and passing it through the logger. (You 
already have it). Adding the following will do the trick (assuming you 
name your parameter in the stored proc as @log_date):
                 <parameter>
                        <parameterName value="@log_date" />
                        <dbType value="DateTime" />
                        <layout type="log4net.Layout.RawTimeStampLayout" 
/>
                 </parameter>

(Yeah! Yeah! I seem to have a little bit of time on my hand today.. :-))

Regards,
Kiran Raja





Kiran Raja/Louisville/Humana
12/29/2004 09:52 AM

To
"Log4NET User" <[email protected]>
cc

Subject
Re: Calling Stored Procedure in CommandText in config file





Hi Pat,

You are welcome! :-) And because you are such a thankful person.. here is 
more help (hopefully) :-) (JK)

I am assuming that you are using the ADO.NET appender to log to some 
database (SQL Server/Oracle etc.). Your commandText value should be the 
stored procedure name and the commandType should be "StoredProcedure".

The following snippet might help you. (It logs to an oracle database using 
datasource DSNAME using a stored procedure pkg_logger.log.

                <appender name="AuditAppender" 
type="log4net.Appender.ADONetAppender">
                        <connectionType 
value="Oracle.DataAccess.Client.OracleConnection, Oracle.DataAccess, 
Version=10.1.0.200, Culture=neutral, PublicKeyToken=89b483f429c47342" />
                        <connectionString value="Data Source=DSNAME;User 
ID=uid;Password=pwd" />
                        <commandText value="pkg_logger.log" />
                        <commandType value="StoredProcedure" />
                        <bufferSize value="1" />

DSNAME is your datasource name. Ex: The TNSORA entry if you are using 
Oracle.

Hope that helps.

Regards,
Kiran Raja.




"Patrick Cheng" <[EMAIL PROTECTED]> 
12/28/2004 10:08 PM
Please respond to
"Log4NET User" <[email protected]>


To
"Log4NET User" <[email protected]>
cc

Subject
Calling Stored Procedure in CommandText in config file






Hi,
  As the subject stated, How can i call a stored proc in the CommandText 
in
a config file?
I have been searching for it, but i'm unable to find a concrete example on
it. The docs simply said
we can write insert statements, or stored proc there. But i failed to
execute my stored proc. (which works
fine if i use insert statement, and the stored proc works fine in sql
analyser)
i tried
   <commandText value="exec testLogging @message"/>
and
   <commandText value="testLogging @message"/>
and they didn't work. certainly the stored proc name is testLogging and it
takes a varchar as parameter.

What am i doing wrong? The simple stored proc contains only an insert
statement..

it works fine when i substitute
   <commandText value="insert into sys_trans_log_header_history
(dealid,groupid,lstUpdDate) values (@message,999, getDate())"/>

Thanks.
Pat

PS: i would like to thank Kiran Raja and Mike Collier for their help in 
the
thread "Question on Logging customized information"




The information transmitted is intended only for the person or entity to which 
it is addressed and may contain CONFIDENTIAL material.  If you receive this 
material/information in error, please contact the sender and delete or destroy 
the material/information.

Reply via email to