如何在log4net中创建自定义级别?

时间:2013-06-10 12:31:21

标签: log4net

如何在Log4Net中创建自定义级别,例如' ERROR ',' WARN ',' INFO '。例如。我想创建一个级别' General ',我想将其用作

logger.General("This is general log");

1 个答案:

答案 0 :(得分:6)

我找到了解决方案。

private static readonly log4net.Core.Level GeneralLevel= new log4net.Core.Level(50000,"General");

log4net.Util.LogLog.InternalDebugging=true;
log4net.LogManager.GetRepository().LevelMap.Add(GeneralLevel);

General("This is Custom Log");

public void General(string message)
{
    Log.Logger.log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,GeneralLevel,message,null);
}