中文字幕在线流畅不卡精品,在线视频综合站,国产精品137页,亚洲制服丝袜中文字幕在

<td id="urspe"></td>
<small id="urspe"><menuitem id="urspe"></menuitem></small><small id="urspe"><sup id="urspe"></sup></small>

  • <small id="urspe"></small>
    <sub id="urspe"><menu id="urspe"><samp id="urspe"></samp></menu></sub>
    我要投稿 投訴建議

    怎么實現(xiàn)日志模塊

    時間:2021-04-13 13:56:26 日志日記 我要投稿

    怎么實現(xiàn)日志模塊

      日志很明顯是幫助大家定位到問題的一個很重要的手段,本來是想直接使用的NLog 來做系統(tǒng)的日志工具,哎傷不起,一變態(tài)非要說這個有很多不可控制的.因素,這里我給大家講一下我是怎么實現(xiàn)日志模塊的,歡迎拍磚.

    怎么實現(xiàn)日志模塊

      總體架構圖

       在這里我把日子的等級分為 跟蹤,BUG 和錯誤 3種 定義枚舉如下

      復制代碼 代碼如下:

      ///

      /// 日志等級

      ///

      public enum Loglevel

      {

      Track=1,

      Bug,

      Error

      }

       這里考慮日志的模塊的可擴展性 (這里支持 數(shù)據(jù)庫 和文件 2種方式) 這里使用適配器模式來完成本模塊。 這里給大家來年終福利。貼點代碼

      定義一個接口ILogTarget

      復制代碼 代碼如下:

      public interface ILogTarget

      {

      ///

      /// 寫入追蹤信息

      ///

      ///

      void WriteTrack(string LogContent);

      ///

      /// 寫入BUG信息

      ///

      ///

      void WriteBug(string LogContent);

      ///

      /// 寫入錯誤信息

      ///

      ///

      void WriteError(string LogContent);

      }

       FileLog ,和DBLog 2個類實現(xiàn)上面的接口 這里不貼上具體的現(xiàn)實

      復制代碼 代碼如下:

      ///

      /// 文件日志實現(xiàn)類

      ///

      public class FileLog : ILogTarget

      {

      public void WriteTrack(string LogContent)

      {

      throw new NotImplementedException();

      }

      public void WriteBug(string LogContent)

      {

      throw new NotImplementedException();

      }

      public void WriteError(string LogContent)

      {

      throw new NotImplementedException();

      }

      }

      復制代碼 代碼如下:

      public class DBLog : ILogTarget

      {

      public void WriteTrack(string LogContent)

      {

      throw new NotImplementedException();

      }

      public void WriteBug(string LogContent)

      {

      throw new NotImplementedException();

      }

      public void WriteError(string LogContent)

      {

      throw new NotImplementedException();

      }

      }

      復制代碼 代碼如下:

      public class SmartLog

      {

      private ILogTarget _adaptee;

      public SmartLog(ILogTarget tragent)

      {

      this._adaptee = tragent;

      }

      public void WriteTrack(string LogContent)

      {

      _adaptee.WriteTrack(LogContent);

      }

      public void WriteBug(string LogContent)

      {

      _adaptee.WriteBug(LogContent);

      }

      public void WriteError(string LogContent)

      {

      _adaptee.WriteError(LogContent);

      }

      }

       調(diào)用方式

      復制代碼 代碼如下:

      SmartLog log =new SmartLog (new FileLog());

      log.WriteTrack("Hello word");

    【怎么實現(xiàn)日志模塊】相關文章:

    還未實現(xiàn)的承諾情感日志12-26

    婆婆的夙愿實現(xiàn)了情感日志05-26

    怎么繼續(xù)日志04-25

    實現(xiàn)自身的價值就要找回真正的自己日志04-22

    一個也許實現(xiàn)不了的夢想日志04-24

    旅游日志怎么寫02-22

    怎么寫旅游日志06-30

    夢不一定要實現(xiàn)優(yōu)秀日志04-26

    怎么實現(xiàn)出國這個夢想?04-13