zoukankan      html  css  js  c++  java
  • Asp.net Core 3.1 之NLog使用扩展

    一、标签介绍

    <variable>标签

    变量定义
    <!-- 定义变量var1-->
    <variable name="var1" value="${basedir}/logs"/>
    <targets>
    <!-- 使用变量var1-->
      <target name="File" xsi:type="File" fileName="${var1}/${shortdate}.txt"/>
    </targets>

     二、辅助类

    class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("---------------------------begin");
                "helper logs debug".Debug();
                "helper logs info".Info();
                "helper logs warn".Warn();
                "helper logs error".Error();
                "helper logs fatal".Fatal();
                Console.WriteLine("---------------------------end");
                Console.ReadKey();
            }
        }
        public static class LogHelper
        {
            private static ILogger logger = GetLogger();
            private static ILogger GetLogger()
            {
                LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"Nlog.config"));
                return LogManager.GetCurrentClassLogger();
            }
    
            /// <summary>
            /// 调试
            /// </summary>
            /// <param name="debug"></param>
            public static void Debug(this string debug)
            {
                logger.Debug(debug);
            }
            /// <summary>
            /// 信息
            /// </summary>
            /// <param name="info"></param>
            public static void Info(this string info)
            {
                logger.Info(info);
            }
    
            /// <summary>
            /// 警告
            /// </summary>
            /// <param name="warn"></param>
            public static void Warn(this string warn)
            {
                logger.Warn(warn);
            }
    
            /// <summary>
            /// 错误
            /// </summary>
            /// <param name="error"></param>
            public static void Error(this string error)
            {
                logger.Error(error);
            }
            /// <summary>
            /// 严重错误
            /// </summary>
            /// <param name="fatale"></param>
            public static void Fatal(this string fatal)
            {
                logger.Fatal(fatal);
            }
    
            /// <summary>
            /// 跟踪
            /// </summary>
            /// <param name="trace"></param>
            public static void Trace(this string trace)
            {
                logger.Trace(trace);
            }
        }
  • 相关阅读:
    close connection error java.sql.SQLRecoverableException: IO Error: Broken pipe
    Mysql 备份与恢复
    MACBOOK 破解wifi密码
    MAC 安装homebrew
    Linux(CentOS / RHEL 7) 防火墙
    ORA-01031: insufficient privileges
    Oracle登录认证
    ORA-12162: TNS:net service name is incorrectly specified
    lsnrctl: .... cannot restore segment prot after reloc: Permission denied
    CentOS / RHEL 配置yum源
  • 原文地址:https://www.cnblogs.com/fger/p/13613521.html
Copyright © 2011-2022 走看看