Return-Path: Delivered-To: apmail-logging-log4net-user-archive@www.apache.org Received: (qmail 39367 invoked from network); 18 Jul 2005 20:36:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 18 Jul 2005 20:36:58 -0000 Received: (qmail 56134 invoked by uid 500); 18 Jul 2005 20:36:57 -0000 Delivered-To: apmail-logging-log4net-user-archive@logging.apache.org Received: (qmail 56116 invoked by uid 500); 18 Jul 2005 20:36:56 -0000 Mailing-List: contact log4net-user-help@logging.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Log4NET User" List-Id: Delivered-To: mailing list log4net-user@logging.apache.org Received: (qmail 56103 invoked by uid 99); 18 Jul 2005 20:36:56 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Jul 2005 13:36:56 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of nicko@neoworks.com designates 80.168.17.114 as permitted sender) Received: from [80.168.17.114] (HELO kronos.neoworks.co.uk) (80.168.17.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Jul 2005 13:36:53 -0700 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 Subject: RE: Type int in ADOAppender. Date: Mon, 18 Jul 2005 21:37:13 +0100 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Type int in ADOAppender. Thread-Index: AcWGZtD6h3v9TF8lRACO5V+POFAAaAFcFOfgAABQPWA= From: "Nicko Cadell" To: "Log4NET User" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N =20 > -----Original Message----- > From: Nicko Cadell [mailto:nicko@neoworks.com]=20 > Sent: 18 July 2005 21:36 > To: Log4NET User > Subject: RE: Type int in ADOAppender. >=20 > The log4net.Layout.PatternLayout generates a string as=20 > output. The IDbDataParameter cannot have its DbType property=20 > set to Int32 and its Value property set to a String. >=20 > You can use the RawPropertyLayout to extract a property value=20 > in its original object form, rather than as a string. >=20 > =20 > =20 > =20 Of course this should have been: =20 > =20 > =20 > =20 > > >=20 > You will have to store the UserID (as an int) in the properties map, > e.g.: >=20 > log4net.ThreadContext.Properties["UserID"] =3D userId; >=20 >=20 > If you want to write your own custom database appender you=20 > can use this as a good starting point: >=20 >=20 > public sealed class FastDbAppender : IAppender, IOptionHandler { > private string m_name; > private string m_connectionString; > private SqlConnection m_dbConnection; >=20 > public string Name > { > get { return m_name; } > set { m_name =3D value; } > } >=20 > public string ConnectionString > { > get { return m_connectionString; } > set { m_connectionString =3D value; } > } >=20 > public void ActivateOptions()=20 > { > m_dbConnection =3D new SqlConnection(m_connectionString); > m_dbConnection.Open(); > } >=20 > public void Close() > { > if (m_dbConnection !=3D null) > { > m_dbConnection.Close(); > } > } >=20 > public void DoAppend(LoggingEvent loggingEvent) > { > SqlCommand command =3D m_dbConnection.CreateCommand(); > command.CommandText =3D "INSERT INTO [LogTable] > ([Time],[Logger],[Level],[Thread],[Message]) VALUES=20 > (@Time,@Logger,@Level,@Thread,@Message)"; >=20 > 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); >=20 > command.ExecuteNonQuery(); > } > } >=20 >=20 > Cheers, >=20 > Nicko >=20 >=20 > > -----Original Message----- > > From: pato43 [mailto:pato43@ig.com.br] > > Sent: 11 July 2005 23:20 > > To: log4net-user@logging.apache.org > > Subject: Type int in ADOAppender. > >=20 > > Dear Friends, > >=20 > > I really tried several times to make my ADOApeender to accept a=20 > > parameter as int, but did not work any time. > >=20 > > The field in my database is an Int. My database is a sqlserver.=20 > > If i change the database type to string, works, when i back to Int,=20 > > doens't work, and any error appears. > >=20 > > This kind of configuration works ok....=20 > > =20 > > =20 > > =20 > > =20 > > =20 > > =20 > > > > > >=20 > > But what i should to do to work with an Int ?=20 > > I try to change the DbType to Int, Int32.=20 > > I try to remove the size parameter and mantain the Dbtype=20 > as string.=20 > > I try to remove the layout parameter... and much more... :)) > >=20 > > Please, help me. I'm going to write my own database logger.=20 > >=20 > > Regards, > >=20 > > Pietro.=20 > > >=20