• Log4Net_LayOut


    对Log4Net做了些基本记录 其中Layout常用参数的解释,我已实例为准。

    测试程序源码如下:

            static void Main(string[] args)
            {
                log4net.Config.XmlConfigurator.Configure();           
                TestMethod();
                Console.WriteLine("OK");
                Console.ReadLine();
            }
    
            private static void TestMethod() {
                TestMethod1();
            }
    
            private static void TestMethod1()
            {
                ILog log = LogManager.GetLogger("MyLogger");
                Exception ex1 = new Exception("内部错误");
                Exception ex2 = new Exception("外部错误", ex1);
                log.Error("发现异常", ex2);
            }
    

     相应的配置,以及结果在下表中

     <conversionPattern value=

               "stacktrace: %stacktrace  
                               stacktracedetail: %stacktracedetail
                               exception: %exception
                               method: %method
                               ndc: %x
                               mdc: %X
                               appdomain:%appdomain:
                               logger: %c
                               type: %C
                               date: %d
                               exception: %d
                               file: %F
                               location: %l
                               line: %L
                               level: %level
                               logger: %logger
                               message: %m
                               property: %property
                               timestamp: %timestamp
                               thread: %thread
                               type: %type                           
                               "
                               />

    stacktrace: Log4NetConsole.Program.TestMethod1  
    stacktracedetail: Log4NetConsole.Program.TestMethod1()
    exception: System.Exception: 外部错误 ---> System.Exception: 内部错误--- 内部异常堆栈跟踪的结尾 ---
    method: TestMethod1
    ndc: (null)
    mdc: {log4net:Identity=, log4net:UserName=YCMSHJack.Xiao, log4net:HostName=DSH07JackXiao}
    appdomain:Log4NetConsole.vshost.exe:
    logger: MyLogger
    type: Log4NetConsole.Program
    date: 2014-06-17 11:35:04,662
    exception: 2014-06-17 11:35:04,662
    file: E:NewCommonDll runkLog4NetTestLog4NetConsoleProgram.cs
    location: Log4NetConsole.Program.TestMethod1(E:NewCommonDll runkLog4NetTestLog4NetConsoleProgram.cs:53)
    line: 53
    level: ERROR
    logger: MyLogger
    message: 发现异常
    property: {log4net:Identity=, log4net:UserName=YCMSHJack.Xiao, log4net:HostName=DSH07JackXiao}
    timestamp: 88
    thread: 9
    type: Log4NetConsole.Program                         

  • 相关阅读:
    将自己的web应用发布到Tomcat
    JavaEE复制后项目出错或者无法运行的解决方法
    Java中eq、ne、ge、gt、le、lt的含义
    Spring中声明式事务处理和编程式事务处理的区别
    Java中获取当前时间并格式化
    Computer Vision Resources
    从信息论到哈弗曼树
    二 图像处理opencv mfc学习
    OpenMP的学习
    图像处理的学习
  • 原文地址:https://www.cnblogs.com/xiaolb/p/3792628.html
Copyright © 2020-2023  润新知