人人妻人人,亚洲人妻丝袜一区电影,日韩少妇熟女专区,午夜欧美成人在线一线天,午夜精品一区二区免费看,一区二区三区综合激情,亚洲99精品热九九,卡一卡二卡三卡四精品在线,miaa-311在线看

怎么實(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

  {

  ///

  /// 寫入追蹤信息

  ///

  ///

  void WriteTrack(string LogContent);

  ///

  /// 寫入BUG信息

  ///

  ///

  void WriteBug(string LogContent);

  ///

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

  ///

  ///

  void WriteError(string LogContent);

  }

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

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

  ///

  /// 文件日志實(shí)現(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();

  }

  }

  復(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

旅游日志怎么寫02-22

怎么寫旅游日志06-30

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

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

哈尔滨市| 黄浦区| 黔江区| 贵定县| 修水县| 建始县| 安丘市| 绥德县| 荣昌县| 从化市| 色达县| 朝阳县| 徐汇区| 镇赉县| 赣榆县| 金坛市| 高清| 九寨沟县| 赣州市| 龙南县| 昭苏县| 和硕县| 老河口市| 叙永县| 达拉特旗| 湖南省| 偃师市| 稷山县| 巴里| 南岸区| 成武县| 柳林县| 荣昌县| 津南区| 东明县| 正安县| 南靖县| 桃园县| 郯城县| 通辽市| 濮阳市|