110,538
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Diagnostics;
using log4net;
namespace myLogTest
{
public class LogMgr
{
private static ILog log = LogManager.GetLogger(MethodInfo.GetCurrentMethod().DeclaringType);
private static string LogPosition()
{
StackTrace st = new StackTrace();
StackFrame sf = st.GetFrame(1);
return "Position:" + sf.GetMethod().DeclaringType.Name+"["+sf.GetMethod().Name+"]\r\n";
}
public static void Error(string message)
{
log.Error(LogPosition()+message);
}
public static void Debug(string message)
{
log.Debug(LogPosition()+ message);
}
public static void Info(string message)
{
log.Info(message);
}
public static void Warn(string message)
{
log.Warn(message);
}
}
}
private void button4_Click(object sender, EventArgs e)
{
StatckTrace st = new StackTrace();
StackFrame sf = st.GetFrame(1);
MessageBox.Show(sf.GetMethod().DeclaringType.Name);
}