Return-Path: Delivered-To: apmail-logging-log4net-user-archive@www.apache.org Received: (qmail 49494 invoked from network); 19 Sep 2005 16:22:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Sep 2005 16:22:24 -0000 Received: (qmail 1852 invoked by uid 500); 19 Sep 2005 16:22:23 -0000 Delivered-To: apmail-logging-log4net-user-archive@logging.apache.org Received: (qmail 1579 invoked by uid 500); 19 Sep 2005 16:22:22 -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 1559 invoked by uid 99); 19 Sep 2005 16:22:22 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Sep 2005 09:22:22 -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: from [80.168.17.114] (HELO hermes.neoworks.co.uk) (80.168.17.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Sep 2005 09:22:31 -0700 Received: from kronos.neoworks.co.uk (kronos.neoworks.co.uk [10.0.0.132]) by hermes.neoworks.co.uk (8.13.1/8.13.1) with ESMTP id j8JGIS5p026178 for ; Mon, 19 Sep 2005 17:18:30 +0100 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: Including datetime stamp in the log messages. X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 Date: Mon, 19 Sep 2005 17:24:42 +0100 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Including datetime stamp in the log messages. Thread-Index: AcW9NNhhE5v+sZbaQROCQe6JThSErAAABx8g 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 How do you want to identify the different log files. I guess it is going to be a combination of action type and some form of unique key. It is no good using the thread ID as the key as threads are reused and you have no control over that at all.=20 If you really want to write to separate files for each action then you should probably have a look at the PatternFileAppender: http://tinyurl.com/7unou http://cvs.apache.org/viewcvs.cgi/logging-log4net/examples/net/1.0/Appen ders/SampleAppendersApp/cs/src/Appender/ This is not shipped as part of the log4net assembly but is a sample file appender that allows the file property to be derived from the logging event. You could configure this appender using log4net's XML configuration as follows: This configuration tells the PatternFileAppender to build up the file name using the ThreadContextProperties 'action' and 'id'. In your code you set these properties like this: log4net.ThreadContext.Properties["action"] =3D "submit"; log4net.ThreadContext.Properties["id"] =3D uniqueIdForRequest; You need to set these properties on the thread that is performing the action you want to log to the file, and you need to set them before any of the logging relating to that action. It is probably best to set the properties to null after the action has finished so that they cannot leak unexpectedly when the runtime reuses your thread. In this way you just create and configure 1 appender and it decided which file to use for each message as it arrives. This should be a lot simpler than creating an appender per action. Nicko > -----Original Message----- > From: Ramaa Davanagere [mailto:RDAVANAG@mobius.com]=20 > Sent: 19 September 2005 17:09 > To: 'Log4NET User' > Subject: RE: Including datetime stamp in the log messages. >=20 >=20 > Well, what I'm trying to accomplish is, to log each=20 > transaction request to a separate log file. Since our=20 > customer support department is going to looking at these log=20 > files, it will be easier if each of the transaction is in a=20 > separate log file. >=20 > With our software, we can do content submission and content=20 > management. So if the user submits a piece of content, I want=20 > to save the log messages pertained to this submit (from start=20 > to end) in one log file.=20 >=20 > If a user changes the content status (or something else) via=20 > content management, I want to save the entire process in a=20 > different log file. >=20 > How can I accomplish this?=20 >=20 >=20 > -----Original Message----- > From: Nicko Cadell [mailto:nicko@neoworks.com] > Sent: Monday, September 19, 2005 11:32 AM > To: Log4NET User > Subject: RE: Including datetime stamp in the log messages.=20 >=20 > The %thread pattern is not evaluated until a message is=20 > logged, then it is evaluated on the thread that is logging.=20 > It is evaluated separately for each message logged as each=20 > message may be logged from a different thread. This may not=20 > be the same thread that is used to configure logging,=20 > therefore the values would be different.=20 >=20 > If you want to get the ID of the current thread=20 > programmatically you can > use:=20 >=20 > AppDomain.GetCurrentThreadId();=20 >=20 > I don't know what you will gain by using the thread id in the=20 > file name, unless you are configuring a separate FileAppender=20 > per thread, which you probably shouldn't be doing.=20 >=20 > Nicko=20 >=20 > > -----Original Message----- > > From: Ramaa Davanagere [mailto:RDAVANAG@mobius.com] > > Sent: 19 September 2005 16:23 > > To: 'Log4NET User'=20 > > Subject: RE: Including datetime stamp in the log messages.=20 > >=20 > >=20 > > Is there a way to read the [%thread] value after its being=20 > > set? What I mean is, after this line is called,=20 > >=20 > > oPatternLayout.ConversionPattern =3D "%date[%thread] %-5level=20 > > %message%newline"; oPatternLayout.ActivateOptions();=20 > >=20 > > Is it possible to do something like this?=20 > >=20 > > String sThreadID =3D oPatterLayout.Property["thread"];=20 > >=20 > > And then use the threadID in my filename.=20 > >=20 > > String sFileName =3D "\myLatestLog_" + sThreadID + ".txt"=20 > > oFileAppender.File =3D @sRootPath + @FileName;=20 > >=20 > > Can I do something like this?=20 > >=20 > > -----Original Message-----=20 > > From: Nicko Cadell [mailto:nicko@neoworks.com]=20 > > Sent: Monday, September 19, 2005 11:11 AM=20 > > To: Log4NET User=20 > > Subject: RE: Including datetime stamp in the log messages.=20 > >=20 > >=20 > > > Thank you! Thank you! Thank you! Thank you!=20 > > >=20 > > > It works. But can you tell me why it needs to be done this=20 > > way? Just=20 > > > curious=20 > >=20 > > http://logging.apache.org/log4net/release/sdk/log4net.Appender=20 > > .FileAppen=20 > > der.ActivateOptions.html=20 > >=20 > >=20 > >=20 > >=20 > > >=20 > > > -----Original Message-----=20 > > > From: Nicko Cadell [mailto:nicko@neoworks.com]=20 > > > Sent: Monday, September 19, 2005 10:36 AM=20 > > > To: Log4NET User=20 > > > Subject: RE: Including datetime stamp in the log messages.=20 > > >=20 > > > Try this:=20 > > >=20 > > >=20 > > > log4net.Appender.FileAppender oFileAppender =3D new=20 > > > log4net.Appender.FileAppender();=20 > > >=20 > > > log4net.Layout.PatternLayout oPatternLayout =3D new=20 > > > log4net.Layout.PatternLayout();=20 > > >=20 > > > oPatternLayout.Header =3D "[Begin]\r\n";=20 > > > oPatternLayout.Footer =3D "[End]\r\n\r\n";=20 > > > oPatternLayout.ConversionPattern =3D "%date[%thread] %-5level=20 > > > %message%newline"; oPatternLayout.ActivateOptions();=20 > > >=20 > > > oFileAppender.Layout =3D oPatternLayout;=20 > > >=20 > > > oFileAppender.File =3D ....=20 > > > oFileAppender.ActivateOptions();=20 > > >=20 > > > Then configure log4net to use the oFileAppender.=20 > > >=20 > > >=20 > > > Cheers,=20 > > > Nicko=20 > > >=20 > > > > -----Original Message-----=20 > > > > From: Ramaa Davanagere [mailto:RDAVANAG@mobius.com]=20 > > > > Sent: 19 September 2005 14:26=20 > > > > To: 'Log4NET User'=20 > > > > Subject: RE: Including datetime stamp in the log messages.=20 > > > >=20 > > > > I'm using log4net 1.2.9.0=20 > > > >=20 > > > > =20 > > > >=20 > > > > Right now, my Fileappender output looks like this=20 > > > >=20 > > > > =20 > > > >=20 > > > > Void=20 > > > > WriteToLog_Info(System.String):busContent.clsSaveContent.Save(=20 > > > > ): After calling CreateContentCache()=20 > > > >=20 > > > > Void=20 > > > > WriteToLog_Info(System.String):busContent.clsSaveContent.Save(=20 > > > > ) - Leaving=20 > > > >=20 > > > > Void=20 > > > > WriteToLog_Info(System.String):busContent.clsRetrieveContent.R=20 > > > > etrieve() - Entering=20 > > > >=20 > > > > =20 > > > >=20 > > > > But I want it to look more like this...=20 > > > >=20 > > > > =20 > > > >=20 > > > > 2005-08-30 08:56:27,968[120048]INFO=20 > > > > busContent.clsSaveContent.Save(): After calling=20 > > CreateContentCache()=20 > > > >=20 > > > > 2005-08-30 08:56:27,968[120049]INFO=20 > > > > busContent.clsSaveContent.Save(): Leaving=20 > > > >=20 > > > > 2005-08-30 08:56:27,968[120050]INFO=20 > > > > busContent.clsRetrieveContent.Retrieve() - Entering=20 > > > >=20 > > > > 2005-08-30 08:57:58,890[129088]ERROR=20 > > > > busContent.clsRetrieveContent.SetVersionNumber(): Object=20 > > > variable not=20 > > > > set=20 > > > >=20 > > > > =20 > > > >=20 > > > > 120049 should be the thread id.=20 > > > >=20 > > > > =20 > > > >=20 > > > > clsSaveContent and clsRetrieveContent are 2 classes of=20 > busContent=20 > > > > component.=20 > > > >=20 > > > > =20 > > > >=20 > > > > I'm more interested in getting the initial part (2005-08-30=20 > > > > 08:56:27,968[120048]INFO) of the message.=20 > > > >=20 > > > > =20 > > > >=20 > > > > =20 > > > >=20 > > > > -----Original Message-----=20 > > > > From: Nicko Cadell [mailto:nicko@neoworks.com]=20 > > > > Sent: Monday, September 19, 2005 9:04 AM=20 > > > > To: Log4NET User=20 > > > > Subject: RE: Including datetime stamp in the log messages.=20 > > > >=20 > > > > =20 > > > >=20 > > > > Which version of log4net are you using?=20 > > > >=20 > > > > =20 > > > >=20 > > > > What does the output of your FileAppender look like at=20 > > the moment?=20 > > > >=20 > > > > =20 > > > >=20 > > > > In your desired output example you have a chunk in square=20 > > > > brackets (e.g.=20 > > > >=20 > > > > [120048]) between the date and the level name, what do you=20 > > > want here?=20 > > > >=20 > > > > Thread ID?=20 > > > >=20 > > > > =20 > > > >=20 > > > > From your example is "Void WriteToLog_Info(System.String)"=20 > > > > part of your=20 > > > >=20 > > > > log message text?=20 > > > >=20 > > > > =20 > > > >=20 > > > > =20 > > > >=20 > > > > Cheers,=20 > > > >=20 > > > > Nicko=20 > > > >=20 > > > > =20 > > > >=20 > > > > > -----Original Message-----=20 > > > >=20 > > > > > From: Ramaa Davanagere [mailto:RDAVANAG@mobius.com]=20 > > > >=20 > > > > > Sent: 19 September 2005 13:56=20 > > > >=20 > > > > > To: 'log4net-user@logging.apache.org'=20 > > > >=20 > > > > > Subject: Including datetime stamp in the log messages.=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > =20 > > > >=20 > > > > >=20 > > > >=20 > > > > > I'm using a fileappender and logging messages to a text file.=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > =20 > > > >=20 > > > > >=20 > > > >=20 > > > > > My Fileappender and PatternLayout are set like this...=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > =20 > > > >=20 > > > > >=20 > > > >=20 > > > > > log4net.Appender.FileAppender oFileAppender =3D new=20 > > > >=20 > > > > > log4net.Appender.FileAppender();=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > log4net.Layout.PatternLayout oPatternLayout =3D new=20 > > > >=20 > > > > > log4net.Layout.PatternLayout();=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > oPatternLayout.Header =3D "[Begin]\r\n";=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > oPatternLayout.Footer =3D "[End]\r\n\r\n";=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > oPatternLayout.ConversionPattern =3D "%d %-5p %c %m%n";=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > =20 > > > >=20 > > > > >=20 > > > >=20 > > > > > But I want the output to look like the sample shown below. I=20 > > > >=20 > > > > > want to include the datetime stamp for each message that is=20 > > > >=20 > > > > > logged to the text file followed by the message type=20 > > > >=20 > > > > > constants (debug, error, fatal, info, etc) and then my=20 > > > log message.=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > =20 > > > >=20 > > > > >=20 > > > >=20 > > > > > 2005-08-30 08:56:27,968[120048]INFO=20 > > > >=20 > > > > > MyCompanyName.MyProductName.ErrorHandler - Void=20 > > > >=20 > > > > > WriteToLog_Info(System.String) about to write a log message=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > 2005-08-30 08:57:58,890[129088]ERROR=20 > > > >=20 > > > > > MyCompanyName.MyProductName.ErrorHandler - Void=20 > > > >=20 > > > > > WriteToLog_Err(System.String): Object variable not set=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > =20 > > > >=20 > > > > >=20 > > > >=20 > > > > > Can somebody look at my conversionPattern string and let me=20 > > > >=20 > > > > > know what is wrong?=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > =20 > > > >=20 > > > > >=20 > > > >=20 > > > > > Thanks.=20 > > > >=20 > > > > >=20 > > > >=20 > > > > > =20 > > > >=20 > > > > >=20 > > > >=20 > > > > >=20 > > > >=20 > > > >=20 > > >=20 > > >=20 > >=20 > >=20 >=20 >=20