Design idea and implementation code of. NET Log System

Source: Internet
Author: User

This article mainly introduces the design idea and implementation code of the. NET log system, and some friends who need it can refer to

The

log is clearly a very important tool to help you navigate the problem. Originally want to use the Nlog to do the system of the log tool, Ah hurt, a pervert must say this has a lot of uncontrollable factors, here I tell you how I realize the Log module, welcome to take the overall structure of the brick  ·    Here I divide the days into tracks, bugs and bugs 3   definitions are enumerated below       code as follows:///<summary>     Log level    ///</summary>     public enum loglevel     {      &NBSP ; Track=1,         bugs,         Error    }  ·    Here consider the log's modulo Block Scalability (2 ways to support databases and files here)   Use adapter mode here to complete this module. Here is the year-end benefits for everyone. The DOT code defines an interface Ilogtarget code as follows: public interface Ilogtarget     {       ///<summary> &N Bsp      ///write tracking information        ///</summary>        ///<param Name= "Logcontent" ></param>         void Writetrack (string logcontent);          ///<summary>        ///write bug information         </summary>        ///<param name= "Logcontent" ></param>         void Writebug (string logcontent);          ///<summary>        ///write error message         </summary>        ///<param name= "logcontent" ></param>       &N Bsp void Writeerror (string logcontent);      }      ·    FileLog, and DBLog 2 classes to implement the above interface here does not post the actual   code as follows:///<summ ary>    ///file Log implementation class    ///</summary>     public class Filelog:ilogtarget &nbsp ;   {        public void Writetrack (string logcontent)         {            throw new NotImplementedException ();        }           public void Writebug (string logcontent)     &NB Sp   {            throw new NotImplementedException () &nbsP      }           public void Writeerror (string logcontent)       & nbsp {            throw new NotImplementedException ()        }   &nbs P The   code is as follows: public class Dblog:ilogtarget     {        public void Writetrack (string L ogcontent)         {            throw new NotImplementedException (); &n Bsp      }           public void Writebug (string logcontent)       &NB Sp {            throw new NotImplementedException ()        }   &nbs P       public void Writeerror (string logcontent)         {        & nbsp   throw new NotImplementedException ();        }     {    code as follows: publicClass Smartlog     {        private ilogtarget _adaptee;           Public Smartlog (Ilogtarget tragent)         {            This._adaptee = Tragent;        }         public void Writetrack (string logcontent)       & nbsp {            _adaptee. Writetrack (logcontent);        }           public void Writebug (string logcontent)     &NB Sp   {            _adaptee. Writebug (logcontent);        }           public void Writeerror (string logcontent)     & nbsp   {            _adaptee. Writeerror (logcontent);        }     {   ·  the way code is as follows: Smartlog log =new smartlog (new FileLog());   Log. Writetrack ("Hello word");

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.