13518219792

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

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

本文转载自微信公众号「UP技术控」,作者conan5566 。转载本文请联系UP技术控公众号。  

公司主营业务:网站设计制作、成都网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出古冶免费做网站回馈大家。

背景

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

配置语法

 
 
 
  1.  
  2.   
  3.           name="String" 
  4.           header="Layout" 
  5.           footer="Layout" 
  6.           layout="Layout" 
  7.           html="Boolean" 
  8.           addNewLines="Boolean" 
  9.           replaceNewlineWithBrTagInHtml="Boolean" 
  10.           encoding="Encoding" 
  11.           subject="Layout" 
  12.           to="Layout" 
  13.           bcc="Layout" 
  14.           cc="Layout" 
  15.           from="Layout" 
  16.           body="Layout" 
  17.           smtpUserName="Layout" 
  18.           enableSsl="Boolean" 
  19.           secureSocketOption="None|Auto|SslOnConnect|StartTls|StartTlsWhenAvailable"* 
  20.           smtpPassword="Layout" 
  21.           smtpAuthentication="Enum" 
  22.           smtpServer="Layout" 
  23.           smtpPort="Integer" 
  24.           useSystemNetMailSettings="Boolean" 
  25.           deliveryMethod="Enum" 
  26.           pickupDirectoryLocation="String" 
  27.           timeout="Integer" 
  28.           skipCertificateValidation="Boolean" 
  29.           priority="Layout" 
  30.  /> 
  31.  

参数

常规选项

可能的值:

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

实现方式

1、vs添加引用NLog.MailKit

2、配置nlog

 
 
 
  1.  
  2.    
  3.      
  4.    
  5.   ... 

3、config配置邮箱信息

 
 
 
  1.  
  2.    
  3.      
  4.        
  5.        
  6.      
  7.    
  8.  

4、配置日志参数

 
 
 
  1.         name="mail" 
  2.         returnToFirstOnSuccess="true"> 
  3.     
  4.             name="mailserver1" 
  5.             subject="Layout" 
  6.             to="Layout" 
  7.             from="Layout" 
  8.             smtpServer="mx1.example.com"  
  9.             smtpPort="Integer" 
  10.             layout="Layout" /> 
  11.     
  12.             name="mailserver2"  
  13.             subject="Layout" 
  14.             to="Layout" 
  15.             from="Layout" 
  16.             smtpServer="mx2.example.com"  
  17.             smtpPort="Integer" 
  18.             layout="Layout" /> 
  19.  
  20.  

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

参考地址

https://github.com/nlog/NLog/wiki/Mail-target


文章标题:日志框架NLog之将日志发送到邮件
分享地址:http://cdbrznjsb.com/article/djoiioo.html

其他资讯

让你的专属顾问为你服务