zoukankan      html  css  js  c++  java
  • NLog的介绍使用

    先参考这个: https://www.cnblogs.com/zhangchengye/p/6297685.html

    补充:

    日志写到json文件中

    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true">
    
      <targets>
    
        <target name="jsonFile" xsi:type="File" fileName="${basedir}/${logger}/${level}/${date:format=yyyy-MM-dd}.json" archiveFileName="${basedir}/${logger}/${level}/log.{#}.json" archiveNumbering="DateAndSequence" archiveAboveSize="10483760" archiveDateFormat="yyyyMMdd" encoding="UTF-8">
          <layout xsi:type="JsonLayout">
            <attribute name="time" layout="${longdate}"/>
            <attribute name="machine" layout="${machinename}"/>
            <attribute name="level" layout="${level:upperCase=true}"/>
            <attribute name="message" layout="${message}" encode="true"/>
          </layout>
        </target>
    
        <target name="warningFile" xsi:type="File" fileName="${basedir}/warn/log.text" archiveFileName="${basedir}/${logger}/${level}/log.{#}.json" archiveNumbering="DateAndSequence" archiveAboveSize="10483760" archiveDateFormat="yyyyMMdd">
          <layout xsi:type="JsonLayout">
            <attribute name="time" layout="${longdate}"/>
            <attribute name="machine" layout="${machinename}"/>
            <attribute name="logger" layout="${logger}"/>
            <attribute name="level" layout="${level:upperCase=true}"/>
            <attribute name="message" layout="${message}"/>
          </layout>
        </target>
    
        <target name="fatalFile" xsi:type="File" fileName="${basedir}/fatal/log.text" archiveFileName="log.{#}.json" archiveNumbering="DateAndSequence" archiveAboveSize="10483760" archiveDateFormat="yyyyMMdd">
          <layout xsi:type="JsonLayout">
            <attribute name="time" layout="${longdate}"/>
            <attribute name="machine" layout="${machinename}"/>
            <attribute name="logger" layout="${logger}"/>
            <attribute name="message" layout="${message}"/>
          </layout>
        </target>
        
      </targets>
    
      <rules>
        <!--<logger name="测试" minlevel="Debug" maxlevel="Error" writeTo="nxlog_json"/>
          <logger name="bar" minlevel="Debug" maxlevel="Error" writeTo="jsonFile"/>
          <logger name="*" levels="Debug,Warn" writeTo="warningFile,jsonFile"/>-->
        <logger name="*" minlevel="Debug" maxlevel="Error" writeTo="jsonFile"/>
      </rules>
    
    </nlog>

    注意:防止汉字转码  为了生成汉字信息:

     换引用 nlog官方默认转义unicode字符 用我重新编译的 DLL NLog.4.4.8_enableUnicodeJson 参考项目:BidSolution 不懂的朋友留言给我!
     
  • 相关阅读:
    select、poll、epoll之间的区别总结[整理]
    IO多路复用之epoll总结
    IO多路复用之select总结
    recv send 阻塞和非阻塞
    undefined reference to `pthread_create' collect2: ld returned 1 exit status
    网络编程 recv()函数
    strlen("汉字")的值是多少
    PPI协议详解 ppi通讯协议 ppi通信协议 vb与ppi协议通讯
    poj1651 Multiplication Puzzle
    poj2240 Arbitrage
  • 原文地址:https://www.cnblogs.com/yechangzhong-826217795/p/9258525.html
Copyright © 2011-2022 走看看