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

如何在Log4Net中创建自定义级别,如'ERROR ', ' WARN ', ' INFO '. eg. I want to create a level ' General',我想将其用作

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

回答(1)

3 years ago

我找到了解决方案

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);
}