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   ; { 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");