Log4net-based Help class log

Source: Internet
Author: User

1 usinglog4net;2 usingSystem;3 usingSystem.Collections.Generic;4 usingSystem.Diagnostics;5 usingSystem.Linq;6 usingsystem.web;7 8 namespaceTrylittle.helper9 {Ten      Public Static classLog One     { A          Public Static voidDebug (Objectmessage) -         { - Logmanager.getlogger (Getcurrentmethodfullname ()). Debug (message); the         } -  -          Public Static voidDebug (Objectmessage, Exception ex) -         { + Logmanager.getlogger (Getcurrentmethodfullname ()). DEBUG (message, ex); -         } +  A          Public Static voidError (Objectmessage) at         { - Logmanager.getlogger (Getcurrentmethodfullname ()). Error (message); -         } -  -          Public Static voidError (Objectmessage, Exception Exception) -         { in Logmanager.getlogger (Getcurrentmethodfullname ()). Error (message, exception); -         } to  +         Private Static stringGetcurrentmethodfullname () -         { the             Try *             { $ stackframe frame;Panax Notoginseng                 stringstr2; -                 intnum =2; theStackTrace trace =NewStackTrace (); +                 intLength =Trace. Getframes (). Length; A                  Do the                 { +frame = trace. GetFrame (num++); -STR2 =frame. GetMethod (). Declaringtype.tostring (); $                 } $                  while(str2. EndsWith ("Exception") && (Num <length)); -                 stringName =frame. GetMethod (). Name; -                 return(STR2 +"."+name); the             } -             CatchWuyi             { the                 return NULL; -             } Wu         } -  About          Public Static voidInfo (Objectmessage) $         { - Logmanager.getlogger (Getcurrentmethodfullname ()). Info (message); -         } -  A          Public Static voidInfo (Objectmessage, Exception ex) +         { the Logmanager.getlogger (Getcurrentmethodfullname ()). Info (message, ex); -         } $  the          Public Static voidWarn (Objectmessage) the         { the Logmanager.getlogger (Getcurrentmethodfullname ()). Warn (message); the         } -  in          Public Static voidWarn (Objectmessage, Exception ex) the         { the Logmanager.getlogger (Getcurrentmethodfullname ()). Warn (message, ex); About         } the  the     } the}
View Code

Note: If you want to use this class in your project, you must first apply Log4net

Log4net-based Help class log

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.