• Nlog.Config:日志方法步骤


    首先添加negut包Nlog.Config:

    安装完毕以后,可以替换Nlog.config

    <?xml version="1.0" encoding="utf-8" ?>
    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
          autoReload="true"
          throwExceptions="false"
          internalLogLevel="Off"
          internalLogFile="c:
    log
    log-internal.log">
    
      <variable name="varDataFolderPath" value="${basedir}/logs"/>
      <variable name="varLayHeader" value="${longdate}|${level}"/>
      <variable name="varLayMiddle" value="${callsite-linenumber}|${callsite:includeSourcePath=false:methodName=false}"/>
      <variable name="varLayBack" value="${message}|${exception:format=toString}"/>
      <targets>
        <target name="logFile"
                xsi:type="File"
                encoding="utf-8"
                maxArchiveFiles="100"
                archiveEvery="Day"
                archiveNumbering="Date"
                archiveDateFormat="yyyyMMdd"
                archiveFileName="${varDataFolderPath}/archives/log.{#}.txt"
                fileName="${varDataFolderPath}/nlog.txt"
                layout="${varLayHeader}|${varLayMiddle}|${varLayBack}" />
        <target xsi:type="Console"
                name="logConsole"
                layout="${varLayHeader}|${varLayMiddle}|${varLayBack}" />
      </targets>
      <rules>
        <logger minlevel="Trace" name="*" writeTo="logFile" />
        <logger minlevel="Trace" name="*" writeTo="logConsole" />
      </rules>
    </nlog>
    View Code

    测试调用:

        private readonly static NLog.ILogger logger = NLog.LogManager.GetCurrentClassLogger(); //zhj-2019-03-28日志
    
    //调用
    
         logger.Trace("开始记录日志....");
         logger.Info("socket Receive:" + servCmd);//zhj-2019-03-28记录日志

    结果会显示在

    记得把Nlog.config改成如果较新则复制

  • 相关阅读:
    Django实现表单验证、CSRF、cookie和session、缓存、数据库多表操作(双下划綫)
    c3p0连接池封装
    关于springboot
    Maven工程
    Servlet 的面试题
    Servlet request 面试题
    spring MVC 核心配置
    日志配置
    mybatis的核心配置文件
    mapper的配置文件
  • 原文地址:https://www.cnblogs.com/aijiao/p/10613424.html
Copyright © 2020-2023  润新知