人人妻人人,亚洲人妻丝袜一区电影,日韩少妇熟女专区,午夜欧美成人在线一线天,午夜精品一区二区免费看,一区二区三区综合激情,亚洲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

垫江县| 岗巴县| 买车| 缙云县| 延津县| 夏邑县| 湘潭市| 乌拉特前旗| 涿州市| 漠河县| 澜沧| 大方县| 云安县| 正宁县| 宁陵县| 嘉禾县| 鄂托克前旗| 侯马市| 孝昌县| 比如县| 航空| 舒城县| 南昌县| 龙南县| 邵阳县| 汉川市| 临颍县| 土默特左旗| 遂昌县| 库尔勒市| 台北市| 板桥市| 德兴市| 平凉市| 米脂县| 金坛市| 上虞市| 广河县| 衢州市| 忻城县| 福贡县|