(.Net) NLog 记录日志功能

本文介绍如何使用NLog框架进行日志记录,包括异常处理和日志配置文件的详细设置,确保应用程序能够有效地记录运行时信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

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>

posted on 2019-09-02 21:42  v.e.n.u.s 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/jx270/p/11449233.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值