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>
  • 相关阅读:
    数据库中导入json数据
    EntityFrameWork Core创建数据库并且使用
    AutoMapper自动映射框架的使用(一)
    值类型和引用类型
    Windows10家庭版安装docker
    Manjaro Linux系统安装
    STM32之USMART的简单介绍
    DSP28335笔记
    张飞第二部:直流无刷电机 直流电源 电感 热水循环泵系统
    高输入阻抗 低输出阻抗 的意义
  • 原文地址:https://www.cnblogs.com/z5337/p/5369004.html
Copyright © 2011-2022 走看看