logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lee Chun Kit <chunki...@gmail.com>
Subject Re: how to catch assembly info from calling function
Date Thu, 17 May 2012 08:36:55 GMT
If you're using the call stack method, do note that JIT optimization may
inline methods, causing the method names to be not what you expect.

Regards,
Chun Kit


On Thu, May 17, 2012 at 4:20 PM, Neil Haughton <
Neil.Haughton@autoscribe.co.uk> wrote:

> If you can wait for C# 5, you will get the Caller functions to deal with
> this!****
>
> ** **
>
> If not, is the call made from a static method in a class or from an
> instance method of that class? If the latter, consider passing the instance
> and method names as an argument (appendLog(this, “thismethodname”, message,
> etc…) then use reflection to discover everything you need to know about it.
> ****
>
> ** **
>
> Also you can interrogate the call stack, which is probably more elegant.
> Information here: (
> http://neilkilbride.blogspot.co.uk/2008/04/how-to-access-call-stack-c.html
> ****
>
> ** **
>
> Best Regards,****
>
> ** **
>
> Neil Haughton BSc MIET IEng(CEI)****
>
> Development Manager
> Autoscribe Limited
> Wellington House,
> Riseley Business Park
> Basingstoke Road, Riseley
> Berkshire RG7 1NW
> Office:   +44 (0) 118 984 0610
> Fax:      +44 (0) 118 984 0611
> Email:  neil.haughton@autoscribe.co.uk    Visit our website at:
> www.autoscribe.co.uk
> Registered in Wales No. 1539748
>
> [image: Description: Description: Description: follow_bird_us-a]<https://twitter.com/#!/autoscribeltd>
> ****
>
> ** **
>
> [image: Description: Description: Description: Description:
> http://press.linkedin.com/images/LinkedIn_WebLogo_LowResExample.jpg]<http://www.linkedin.com/company/417914?trk=pro_other_cmpy>
>
> **********************************************************DISCLAIMER*****************************************************
>
> The contents of this email are confidential and are intended solely for
> the use of the individual or company to
> whom it is addressed. If you have received this email in error then please
> accept our apology. If this is the case
> we would be obliged if you would contact the sender and then delete this
> email. Opinions expressed in this email
> are those of the individual and do not necessarily represent the opinions
> of Autoscribe Ltd. Although this email
> and any attachments are believed to be free of any virus no responsibility
> is accepted by Autoscribe Ltd for any
> loss or damage arising in any way from the receipt or use of this email or
> attachments.****
>
> ** **
>
> ** **
>
> ** **
>
> *From:* Alex Misca [mailto:alex.misca@sibpharmamed.ro]
> *Sent:* 17 May 2012 08:40
> *To:* log4net-user@logging.apache.org
> *Subject:* how to catch assembly info from calling function****
>
> ** **
>
> Hy,****
>
> ** **
>
> I have a static function which calls logg.info or logger.debug and so on,
> depending of where I call it. How can I save into log file the class and
> line from where I called the function. Logger writes the class/line from
> the function I created not from the call made.****
>
> ** **
>
> Example:****
>
> ** **
>
> In a static class****
>
> ** **
>
> *public* static void *appendLog*(string messageType, string message, Exception
> exc)
>         {
>             messageType = messageType.*ToUpper*();
>             *switch*(messageType)
>             {
>                 *case* "INFO":
>                     {
>                         *if* (exc == *null*)
>                         {
>                             MainForm.logger.*Info*(message);
>                         }
>                         *else*
>                         {
>                             MainForm.logger.*Info*(message, exc);
>                         }
>                         break;
>                     }
>                 *case* "DEBUG":
>                 {
>                     *if* (exc == *null*)
>                     {
>                         MainForm.logger.*Debug*(message);
>                     }
>                     *else*
>                     {
>                         MainForm.logger.*Debug*(message, exc);
>                     }
>                     break;
>                 }
>                 *case* "ERROR":
>                     {
>                         *if* (exc == *null*)
>                         {
>                             MainForm.logger.*Error*(message);
>                         }
>                         *else*
>                         {
>                             MainForm.logger.*Error*(message, exc);
>                         }
>                         break;
>                     }
>                 *case* "FATAL":
>                 {
>                     *if* (exc == *null*)
>                     {
>                         MainForm.logger.*Fatal*(message);
>                     }
>                     *else*
>                     {
>                         MainForm.logger.*Fatal*(message, exc);
>                     }
>                     break;
>                 }
>                 *case* "WARNING":
>                 {
>                     *if* (exc == *null*)
>                     {
>                         MainForm.logger.*Warn*(message);
>                     }
>                     *else*
>                     {
>                         MainForm.logger.*Warn*(message, exc);
>                     }
>                     break;
>                 }
>                 *default*:
>                     break;
>             }
>         }****
>
> ** **
>
> ** **
>
> from another class I call:****
>
> ** **
>
> *appendLog*("error","Exception thrown", exc);****
>
> ** **
>
> the logger saves class/line from the static class and I want it to save
> the assembly info from the calling class.****
>
> ** **
>
> Can it be done?****
>
> ** **
>
> (code is an example… not final )****
>
> ** **
>
> Thanks****
>

Mime
View raw message