Thanks for the quick reply.
I was thinking of using stacktrace and will probably go with it. Although it's not the best solution since I'm using log4net adonetadapter and wanted to populate my table fields according to log4net output for readabillity. At least until c# 5. Kind regards, Alex Misca From: Neil Haughton [mailto:neil.haugh...@autoscribe.co.uk] Sent: Thursday, May 17, 2012 11:20 AM To: Log4NET User Subject: RE: how to catch assembly info from calling function 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.haugh...@autoscribe.co.uk Visit our website at: www.autoscribe.co.uk <http://www.autoscribe.co.uk/> Registered in Wales No. 1539748 <https://twitter.com/#!/autoscribeltd> Description: Description: Description: follow_bird_us-a <http://www.linkedin.com/company/417914?trk=pro_other_cmpy> Description: Description: Description: Description: http://press.linkedin.com/images/LinkedIn_WebLogo_LowResExample.jpg **********************************************************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.mi...@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
<<image001.png>>
<<image002.jpg>>