Thanks for the update on this. However I am not sure how to go about it.
I am adding the custom parameters to the MDC stack as follows.
MDC.set("IntegerVarName", value);
However this method only allows the value parameter to be a type string.
I want to add an integer to the stack do I have to do it a different way
for non-string data types? Below is my current code.
Thanks,
Brette
MDC.Set("methodName", inMethodName);
MDC.Set("className", inClassName);
//This will only allow a string how do I pass an integer to the
framework?
MDC.Set("applicationId", inApplicationId);
internalLogger.Debug(inMessage);
<commandText value="INSERT INTO Log (APPLICATIONID, CLASSNAME,
METHODNAME, LOGLEVEL, LOGGER, MESSSAGE) VALUES (:Application_Id,
Translate(:Method_Name using CHAR_CS), Translate(:Class_Name using
CHAR_CS), Translate(:log_level using CHAR_CS), Translate(:logger using
CHAR_CS), Translate(:message using CHAR_CS))" />
<bufferSize value="1" />
<parameter>
<dbType value="Int32" />
<parameterName value=":Application_Id" />
<layout type="log4net.Layout.RawPropertyLayout">
<conversionPattern
value="%X{applicationId}" />
</layout>
</parameter>
Etc.
-----Original Message-----
From: Nicko Cadell [mailto:[EMAIL PROTECTED]
Sent: Monday, July 18, 2005 3:37 PM
To: Log4NET User
Subject: RE: Type int in ADOAppender.
> -----Original Message-----
> From: Nicko Cadell [mailto:[EMAIL PROTECTED]
> Sent: 18 July 2005 21:36
> To: Log4NET User
> Subject: RE: Type int in ADOAppender.
>
> The log4net.Layout.PatternLayout generates a string as
> output. The IDbDataParameter cannot have its DbType property
> set to Int32 and its Value property set to a String.
>
> You can use the RawPropertyLayout to extract a property value
> in its original object form, rather than as a string.
>
> <param name="Parameter">
> <param name="ParameterName" value="@userID" />
> <param name="DbType" value="String" />
Of course this should have been:
<param name="DbType" value="Int32" />
> <param name="Size" value="40" />
> <param name="Layout" type="log4net.Layout.RawPropertyLayout">
> <param name="Key" value="UserID" />
> </param>
> </param>
>
> You will have to store the UserID (as an int) in the properties map,
> e.g.:
>
> log4net.ThreadContext.Properties["UserID"] = userId;
>
>
> If you want to write your own custom database appender you
> can use this as a good starting point:
>
>
> public sealed class FastDbAppender : IAppender, IOptionHandler {
> private string m_name;
> private string m_connectionString;
> private SqlConnection m_dbConnection;
>
> public string Name
> {
> get { return m_name; }
> set { m_name = value; }
> }
>
> public string ConnectionString
> {
> get { return m_connectionString; }
> set { m_connectionString = value; }
> }
>
> public void ActivateOptions()
> {
> m_dbConnection = new SqlConnection(m_connectionString);
> m_dbConnection.Open();
> }
>
> public void Close()
> {
> if (m_dbConnection != null)
> {
> m_dbConnection.Close();
> }
> }
>
> public void DoAppend(LoggingEvent loggingEvent)
> {
> SqlCommand command = m_dbConnection.CreateCommand();
> command.CommandText = "INSERT INTO [LogTable]
> ([Time],[Logger],[Level],[Thread],[Message]) VALUES
> (@Time,@Logger,@Level,@Thread,@Message)";
>
> command.Parameters.Add("@Time", loggingEvent.TimeStamp);
> command.Parameters.Add("@Logger",
> loggingEvent.LoggerName);
> command.Parameters.Add("@Level",
> loggingEvent.Level.Name);
> command.Parameters.Add("@Thread",
> loggingEvent.ThreadName);
> command.Parameters.Add("@Message",
> loggingEvent.RenderedMessage);
>
> command.ExecuteNonQuery();
> }
> }
>
>
> Cheers,
>
> Nicko
>
>
> > -----Original Message-----
> > From: pato43 [mailto:[EMAIL PROTECTED]
> > Sent: 11 July 2005 23:20
> > To: [email protected]
> > Subject: Type int in ADOAppender.
> >
> > Dear Friends,
> >
> > I really tried several times to make my ADOApeender to accept a
> > parameter as int, but did not work any time.
> >
> > The field in my database is an Int. My database is a sqlserver.
> > If i change the database type to string, works, when i back to Int,
> > doens't work, and any error appears.
> >
> > This kind of configuration works ok....
> > <param name="Parameter">
> > <param name="ParameterName" value="@userID" />
> > <param name="DbType" value="String" />
> > <param name="Size" value="40" />
> > <param name="Layout" type="log4net.Layout.PatternLayout">
> > <param name="ConversionPattern" value="%x" />
> > </param>
> > </param>
> >
> > But what i should to do to work with an Int ?
> > I try to change the DbType to Int, Int32.
> > I try to remove the size parameter and mantain the Dbtype
> as string.
> > I try to remove the layout parameter... and much more... :))
> >
> > Please, help me. I'm going to write my own database logger.
> >
> > Regards,
> >
> > Pietro.
> >
>