zoukankan      html  css  js  c++  java
  • Nlog Layout

    Nlog.config

      
      <targets>
        <target type="Console" name="trace" layout="${message}${newline}${onexception:inner=${newline} *****Error***** ${newline} ${exception:format=toString}${exception:format=StackTrace}}"/>
      </targets>

    主要Layout这段,当不是异常的时候显示Message,异常时候显示异常类型和StackTrace

    也可加入${stacktrace},平时也可以显示Stacktrace。

    private static void aa()
            {
                var logger = LogManager.GetCurrentClassLogger();
                
                
                logger.Info("Hello1");
                logger.Info("Hello2");
                logger.Info("Hello3");
                try{
                    throw new Exception("Test Exception",new Exception("Inner"));
                }
                catch(Exception error)
                {
                        logger.InfoException("error1",error);
                
                
                }
            
                
            }

    输出

    Hello1
    Hello2
    Hello3
    error1
    *****Error*****
    System.Exception: Test Exception ---> System.Exception: Inner
    --- 内部异常堆栈跟踪的结尾 ---
    在 testNlog.Program.aa() 在 testNlog.Program.aa()

  • 相关阅读:
    os模块
    sys模块
    time时间模块
    collections模块
    修改Jenkins的主目录步骤
    jenkins管理
    求2个集合的差集
    MVC动态二级域名解析
    解决MVC 时间序列化的方法
    MVC修改视图的默认路径
  • 原文地址:https://www.cnblogs.com/peteryu007/p/4218286.html
Copyright © 2011-2022 走看看