• 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);
            }
        }
  • 相关阅读:
    11C++11通用为本,专用为末_2
    10C++11通用为本,专用为末_1
    09C++11保证稳定性和兼容性
    21变量名的力量_2
    NOIP2018 游记
    CF767C 经典的树形DP
    CF1A Theatre Square
    洛谷P1720 月落乌啼算钱
    洛谷P3388 缩点
    NOIP2017D2T1 奶酪 洛谷P3958
  • 原文地址:https://www.cnblogs.com/fger/p/13613521.html
Copyright © 2020-2023  润新知