標籤:play getc ssl .net core pac lan 應該 str private
在.net standard 2.0.3 和.net core 2.1適用。其他版本的.net 應該也可以。
1.建立一個空白解決方案,再建一個類庫
2.安裝NLog.Config,會產生一個設定檔NLog.config
3.將預設注釋的代碼複製一份出來
4.建立一個LogHelper類
1 namespace Demo.Utility 2 { 3 /// <summary> 4 /// Nlog日誌協助類 5 /// </summary> 6 public class LogHelper 7 { 8 private static Logger logger = LogManager.GetCurrentClassLogger(); //初始化日誌類 9 10 /// <summary>11 /// 調試日誌12 /// </summary>13 /// <param name="msg">日誌內容</param>14 public static void Debug(string msg)15 {16 logger.Debug(msg);17 }18 19 /// <summary>20 /// 資訊日誌21 /// </summary>22 /// <param name="msg">日誌內容</param>23 public static void Info(string msg)24 {25 logger.Info(msg);26 }27 28 /// <summary>29 /// 錯誤記錄檔30 /// </summary>31 /// <param name="msg">日誌內容</param>32 public static void Error(string msg)33 {34 logger.Error(msg);35 }36 37 /// <summary>38 /// 嚴重致命錯誤記錄檔39 /// </summary>40 /// <param name="msg">日誌內容</param>41 public static void Fatal(string msg)42 {43 logger.Fatal(msg);44 }45 46 /// <summary>47 /// 警告日誌48 /// </summary>49 /// <param name="msg">日誌內容</param>50 public static void Warn(string msg)51 {52 logger.Warn(msg);53 }54 55 /// <summary>56 /// 追蹤日誌57 /// </summary>58 /// <param name="msg">日誌內容</param>59 public static void Trace(string msg)60 {61 logger.Trace(msg);62 }63 }64 }
View Code
5.建立一個.net core API來使用一下
6.可以看到產生的日誌。預設是在運行目錄下,可以在NLog.config配置組建目錄和格式
NLog官網:https://nlog-project.org/
.net core 中使用NLog