码迷,mamicode.com
首页 > 其他好文 > 详细

[Nlog]使用经验

时间:2016-04-08 18:09:17      阅读:368      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <targets async="true">
    <target name="csv" xsi:type="File" fileName="${basedir}/logs/${windows-identity:domain=false}_${shortdate}.csv">
      <layout xsi:type="CSVLayout">
        <column name="time" layout="${longdate}" />
        <column name="level" layout="${level}"/>
        <column name="logger" layout="${logger}"/>
        <column name="message" layout="${message}" />
      </layout>
    </target>
    
    <!-- write logs to file -->
    <target name="file" xsi:type="File" fileName="${basedir}/logs/${windows-identity:domain=false}.txt"
        layout="${longdate} ${logger} ${message}" />
    
    <!-- send mail through GMail server -->
    <target xsi:type="Mail"
            name="mail"
            smtpServer="smtp.163.com"
            smtpPort="25"
            enableSsl="false"
            smtpAuthentication="Basic"
            smtpUserName=""
            smtpPassword="111111"
            from="@163.com"
            to="qq.com"
            subject="NLogDemo Test"
            addNewLines="true"
            body="${longdate}"
            />

    <!-- send mail asynchronously, so that it does not block the calling thread -->
    <wrapper-target xsi:type="AsyncWrapper" name="asyncMail">
      <target-ref name="mail"/>
    </wrapper-target>
  </targets>
  <rules>
    <!-- Trace|Debug|Info|Warn|Error|Fatal -->
    <logger name="*" minlevel="Info" writeTo="mail" />
    <logger name="*" minlevel="Warn" writeTo="csv" />
    <logger name="*" minlevel="Error" writeTo="mail" />
  </rules>
</nlog>
View Code

发送邮件级别需要调整,目前测试 SSL 发不出邮件,可能 NLog 自身原因

[Nlog]使用经验

标签:

原文地址:http://www.cnblogs.com/z5337/p/5369004.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!