NLog 简单使用
1.安裝NLog? 使其集成到VS 里??下載地址: http://nlog-project.org/
2.NLog.config
<?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><!-- make sure to set 'Copy To Output Directory' option for this file --><!-- go to http://nlog-project.org/wiki/Configuration_file for more information --><targets><target name="file" xsi:type="File" fileName="${basedir}/log/${shortdate}.txt"layout="${longdate} ${stacktrace} ${message}"/></targets><rules><logger name="*" minlevel="Debug" writeTo="file" /></rules> </nlog>?
3.創(chuàng)建
private static Logger logger = LogManager.GetCurrentClassLogger();4.記錄錯誤信息
每條跟蹤信息都包含一個記錄等級(log level)信息,用來描述該條信息的重要性。NLog支持如下幾種記錄等級:
例如:
try{int i = 9;int j = 0;int y = i / j; //試圖除以0int[] arr = {2,5,5,8,6,9,3,7 };for (int n = 0; n < 12; i++)//索引超出了數(shù)組界限
{int m = arr[n];}}catch (Exception ex){logger.Error(ex.Message);Response.Write("Error");}
更多內(nèi)容參考:http://www.cnblogs.com/dflying/archive/2006/12/05/583071.html
轉(zhuǎn)載于:https://www.cnblogs.com/JiangXiaoTian/articles/2557914.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
- 上一篇: 运用递归实现快速排序算法(二分排序)
- 下一篇: 浅谈机器学习-分类和聚类的区别