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");
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.
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.
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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With