对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
|