zoukankan      html  css  js  c++  java
  • .Net Core使用NLog自定义日志存储路径

    1.安装NLog、NLog.Config包

    2.添加日志类

    public class LogFactory
        {
            public static Logger log;
            private string filename;
    
            /// <summary>
            /// 日志类
            /// </summary>
            /// <param name="filename">文件夹名称</param>
            public LogFactory(string filename)
            {
                this.filename = filename;
                 log = LogManager.GetCurrentClassLogger(); 
            }
            public void Info(string message)
            {
                log.WithProperty("filename", filename).Info(message);
            }
            public void Error(string message)
            {
                log.WithProperty("filename", filename).Error(message);
            }
            public void Debug(string message)
            {
                log.WithProperty("filename", filename).Debug(message);
            }
            
            ...... //根据需要自己添加
        }
    

      

    3. NLog.Config配置文件

      <targets>
    
        <!--
        add your targets here
        See https://github.com/nlog/NLog/wiki/Targets for possible targets.
        See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
       --> <target xsi:type="File" name="f" fileName="${basedir}/logs/${event-properties:filename}/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" /> </targets>

    4.调用方法

     public void test(){
        LogFactory logger = new LogFactory(route); // route指自定义文件夹名字          
          logger.Info("日志信息");  //记录输入的请求的参数
      }   
    

      

  • 相关阅读:
    php单例设计模式
    js实用技巧
    快速排序java实现
    PHP大小写问题
    http转https
    wx-charts 微信小程序图表插件
    如何判断微信内置浏览器 MicroMessenger
    小程序:下拉加载更多时bindscrolltolower多次执行
    PHP内核
    CSS的4种引入方式以及优先级
  • 原文地址:https://www.cnblogs.com/besos/p/13384165.html
Copyright © 2011-2022 走看看