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 不懂的朋友留言给我!
 

转载于:https://www.cnblogs.com/yechangzhong-826217795/p/9258525.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值