zoukankan      html  css  js  c++  java
  • [Nlog]使用经验

    <?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 纠结,原来是 NLog.config 要配置为:复制到输出目录 > 始终复制

    <?xml version="1.0" ?>
    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          autoReload="true">
      <!-- 本文参考: http://www.cnblogs.com/dflying/archive/2006/12/15/593158.html -->
      <targets async="true">
        <!-- write logs to file -->
        <!-- ${date:format=yyyyMMdd HH:mm:ss.fff} -->
        <target name="file" xsi:type="File" fileName="${basedir}/log/${shortdate}.txt"
                layout="${time} [${threadid}] [${uppercase:${level}}] ${logger} ${stacktrace:format=Flat} ${message}" />
        
        <!-- send mail -->
        <target name="mail" xsi:type="Mail"            
                smtpServer="smtp.163.com"
                smtpAuthentication="Basic"
                smtpUserName="17007700728"
                smtpPassword="--"
                from="17007700728@163.com"
                to="--"
                subject="NLog ${processname} ${assembly-version}"
                addNewLines="true"
                header="===== ${machinename} ${logger} ====="
                body="${longdate} [${uppercase:${level}}] ${stacktrace} ${message}"
                footer="===== END ====="
                />
      </targets>
      <rules>
        <!-- Trace|Debug|Info|Warn|Error|Fatal -->
        <logger name="*" writeTo="file" />
        <logger name="*" minlevel="Warn" writeTo="mail" />
      </rules>
    </nlog>
  • 相关阅读:
    用Ajax将checkbox选中的值发送给后台
    checkbox选中selec才可选和显示隐藏密码
    删除表格当前行
    Ajax本地取模板--完善窗口隐藏与共用
    Ajax向服务器请求对表单和表格进行操作
    用原生Dom实现向表格中添加数据
    正则判断表单输入
    隐藏窗口弹出及拖动效果
    原生DOM操作两个栗子,关于折叠内容和批量删除
    学习JS处理全选过程中遇到很多问题,所以把这个写了出来,希望对需要的人有帮助
  • 原文地址:https://www.cnblogs.com/z5337/p/5369004.html
Copyright © 2011-2022 走看看