• 日志框架Nlog之异步记录


    日志功能本来是一件非常好的事情,能帮助我们分析和解决很多问题。但是,如果让日志影响到性能,这就需要权衡一下了。没关系,本篇博客咱们不仅来解决这个问题,咱们更要眼见为实,带图带真相让你用的明明白白。

    日志实现异步功能

               其实呢就一句话。。

               配置文件targets中配置async="true"即为异步。默认或写false都为同步。

    例如:

    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true">
    
      <targets async="true">
    
        <target name="jsonFile" xsi:type="File" fileName="${basedir}/logs/${level}/${date:format=yyyy-MM-dd}.json" archiveFileName="${basedir}/logs/${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}"/>
            <!--<attribute name="cost" layout="${mdc:item=cost}"/>
            <attribute name="nested">
              <layout type="JsonLayout">
                <attribute name="message" layout="${message}"/>
                <attribute name="exception" layout="${exception}"/>
              </layout>
            </attribute>-->
          </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>
  • 相关阅读:
    本来一行可以代替的树节点搜索
    mssql 重新开始标识
    TabContainer实现服务器端回传
    CSS中图片路径的问题
    Javascript在IE下设置innerHTML时出现"未知的运行时错误"
    sql union和union all的用法及效率
    关于动态添加TabPanel遇到的问题以及思考
    关于linq to sql调用存储过程,出现"无法枚举查询结果多次"的问题
    SQL Server 2005连接服务器时的26号错误解决!
    SQL 2000和2005 获取两表的差集
  • 原文地址:https://www.cnblogs.com/yechangzhong-826217795/p/14538617.html
Copyright © 2020-2023  润新知