日志框架NLog之怎么将日志发送到邮件

发布时间:2021-10-19 09:17:55 作者:iii
来源:亿速云 阅读:117

这篇文章主要讲解了“日志框架NLog之怎么将日志发送到邮件”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“日志框架NLog之怎么将日志发送到邮件”吧!

背景

NLog可以将日志输出到不同的媒介上,邮件是其中一个,通过邮件可以让我们第一时间收到信息。使用SMTP协议通过电子邮件发送日志消息。与FallbackGroup  Target很好地结合在一起,以创建具有多个SMTP主机的后备。

配置语法

<targets>   <target xsi:type="Mail"           name="String"           header="Layout"           footer="Layout"           layout="Layout"           html="Boolean"           addNewLines="Boolean"           replaceNewlineWithBrTagInHtml="Boolean"           encoding="Encoding"           subject="Layout"           to="Layout"           bcc="Layout"           cc="Layout"           from="Layout"           body="Layout"           smtpUserName="Layout"           enableSsl="Boolean"           secureSocketOption="None|Auto|SslOnConnect|StartTls|StartTlsWhenAvailable"*           smtpPassword="Layout"           smtpAuthentication="Enum"           smtpServer="Layout"           smtpPort="Integer"           useSystemNetMailSettings="Boolean"           deliveryMethod="Enum"           pickupDirectoryLocation="String"           timeout="Integer"           skipCertificateValidation="Boolean"           priority="Layout"  /> </targets>

参数

常规选项

可能的值:

skipCertificateValidation-仅适用于NLog.MailKit。在NLog.MailKit 1.1中引入-跳过SSL认证检查

实现方式

1、vs添加引用NLog.MailKit

2、配置nlog

<nlog>   <extensions>     <add assembly="NLog.MailKit"/>   </extensions>   ...

3、config配置邮箱信息

<system.net>   <mailSettings>     <smtp from="mail@domain.com" deliveryMethod="SpecifiedPickupDirectory">       <network host="localhost" port="25"/>       <specifiedPickupDirectory pickupDirectoryLocation="C:/Temp/Email"/>     </smtp>   </mailSettings> </system.net>

4、配置日志参数

<target xsi:type="FallbackGroup"          name="mail"         returnToFirstOnSuccess="true">     <target xsi:type="Mail"             name="mailserver1"             subject="Layout"             to="Layout"             from="Layout"             smtpServer="mx1.example.com"              smtpPort="Integer"             layout="Layout" />     <target xsi:type="Mail"             name="mailserver2"              subject="Layout"             to="Layout"             from="Layout"             smtpServer="mx2.example.com"              smtpPort="Integer"             layout="Layout" />  </target>

最后就可以收到日志邮件啦。

感谢各位的阅读,以上就是“日志框架NLog之怎么将日志发送到邮件”的内容了,经过本文的学习后,相信大家对日志框架NLog之怎么将日志发送到邮件这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. golang日志框架之logrus的使用
  2. MyBatis日志为什么可以兼容其他的日志框架

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

nlog

上一篇:怎么编写Python爬虫爬取B站小视频的源码

下一篇:怎么实现php策略模式

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》