Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create custom level in log4net?

Tags:

log4net

How to create a custom level in Log4Net like 'ERROR', 'WARN', 'INFO'. eg. I want to create a level 'General' and I want to use it as

logger.General("This is general log");
like image 955
Ramesh Avatar asked Jun 10 '13 12:06

Ramesh


People also ask

What is level value in log4net?

log4net offers the following log levels, in increasing order of priority: ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF. The ALL level logs everything and the OFF level logs nothing. You can assign these log levels to each logger in your configuration file.

How do I initialize log4net?

Configuration InitializationConfigureAndWatch to initialize log4net setup as per the config setup in your main entry method like main method of program class. Method “ ConfigureAndWatch ” configures log4net using the file specified, monitors the file for changes and reloads the configuration if a change is detected.

What is fatal log level?

The FATAL level of logging shows that the application's situation is catastrophic, such that an important function is not working. For example, you can use FATAL log level if the application is unable to connect to the data store.


1 Answers

I found solution.

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);
}
like image 82
Ramesh Avatar answered Sep 20 '22 03:09

Ramesh