Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Know the current log level using log4net to store in database

Tags:

c#

.net

log4net

How to Know the current log level using log4net to store in database in an application.

like image 840
user1001282 Avatar asked Feb 23 '23 16:02

user1001282


1 Answers

If you mean the enabled levels then:

bool IsDebugEnabled { get; }
bool IsInfoEnabled { get; }
bool IsWarnEnabled { get; }
bool IsErrorEnabled { get; }
bool IsFatalEnabled { get; }

if all of them are true then the level would be Debug, if Info and above is enabled then it is info and so ..

you can check like this

if(myLogger.IsDebugEnabled)
  return "Debug";
else if(myLogger.IsInfoEnabled)
  return "Info";
else if(myLogger.IsWarnEnabled)
  return "Warn";
else if(myLogger.IsErrorEnabled)
  return "Error";
else if(myLogger.IsFatalEnabled)
  return "Fatal";
else
  return "None";

You can also get the specific level by this:

((log4net.Repository.Hierarchy.Logger)mylogger.Logger).Level
like image 85
Mohamed Abed Avatar answered Apr 27 '23 11:04

Mohamed Abed