首页 > Web开发 > 详细

(.Net) NLog 记录日志功能

时间:2019-09-02 22:09:56      阅读:101      评论:0      收藏:0      [点我收藏+]

 

https://codeload.github.com/NLog/NLog/zip/v4.6.6

https://nlog-project.org/?r=redirect

 

Logger logger = LogManager.GetCurrentClassLogger();

logger.Info("Move Return Receive Json :" + request);

catch (Exception ex)
{
//抛出异常,给出异常信息
db.RollbackTrans();
UpdateExceptionReqData(requestObj, retryCnt, ex.Message.ToString()); // update request error
responseObj.Message = ex.Message;
responseObj.Status = "1";
logger.Error(ex.Message);
}

 

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" autoReload="true">

<!-- 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="d://Logs/WebApi/${shortdate}/${aspnetmvc-controller}/WebApi_${shortdate}_${aspnetmvc-controller}.txt" />
<extensions>
<add assembly="NLog.Extended"/>
</extensions>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
</rules>
</nlog>

(.Net) NLog 记录日志功能

原文:https://www.cnblogs.com/jx270/p/11449233.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!