寡妇张开腿让黑人通爽,吃瓜黑料,欧美激情内射喷水高潮,亚洲精品午夜国产va久久成人

我要投稿 投訴建議

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

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

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

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

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

  總體架構(gòu)圖

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

  復(fù)制代碼 代碼如下:

  ///

  /// 日志等級(jí)

  ///

  public enum Loglevel

  {

  Track=1,

  Bug,

  Error

  }

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

  定義一個(gè)接口ILogTarget

  復(fù)制代碼 代碼如下:

  public interface ILogTarget

  {

  ///

  /// 寫(xiě)入追蹤信息

  ///

  ///

  void WriteTrack(string LogContent);

  ///

  /// 寫(xiě)入BUG信息

  ///

  ///

  void WriteBug(string LogContent);

  ///

  /// 寫(xiě)入錯(cuò)誤信息

  ///

  ///

  void WriteError(string LogContent);

  }

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

  復(fù)制代碼 代碼如下:

  ///

  /// 文件日志實(shí)現(xiàn)類(lèi)

  ///

  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();

  }

  }

  復(fù)制代碼 代碼如下:

  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();

  }

  }

  復(fù)制代碼 代碼如下:

  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)用方式

  復(fù)制代碼 代碼如下:

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

  log.WriteTrack("Hello word");

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

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

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

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

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

一個(gè)也許實(shí)現(xiàn)不了的夢(mèng)想日志04-24

旅游日志怎么寫(xiě)02-22

怎么寫(xiě)旅游日志06-30

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

怎么實(shí)現(xiàn)出國(guó)這個(gè)夢(mèng)想?04-13

灵石县| 榆社县| 武隆县| 安宁市| 成安县| 馆陶县| 郴州市| 谷城县| 邵东县| 阿坝县| 和林格尔县| 长顺县| 五台县| 双牌县| 江西省| 南溪县| 内黄县| 塔河县| 阿图什市| 江津市| 岳普湖县| 运城市| 宜章县| 长岭县| 潼南县| 望奎县| 海盐县| 渑池县| 无锡市| 体育| 贵溪市| 屏东县| 石屏县| 宜川县| 拉孜县| 东阳市| 呈贡县| 师宗县| 通江县| 高雄市| 凤庆县|