Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing log level without restarting application

It is possible to change log4net logging level without restart ASP.NET application. Some possible ways to configure log4net configuration are:

  • ASP.NET web config file.
  • adding separate config file and referring config file inside AssemblyInfo.cs file: [assembly:log4net.Config.XmlConfigurator(ConfigFile="Log4Net.config",Watch=true)]

Changing the configuration in a web.config file will restart the application. If I don't want to restart the application, is it recommended to use the separate configuration file or is there any different approach for this?

like image 328
Mahesh Avatar asked Feb 02 '15 05:02

Mahesh


People also ask

How do you change the log level?

To change log levels as a root user, perform the following: To enable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=DEBUG) To disable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=INFO)

How do you change the log level in log4j2 at runtime?

You can set a logger's level with the class Configurator from Log4j Core. BUT be aware that the Configurator class is not part of the public API. If you wish to change the root logger level, do something like this : LoggerContext ctx = (LoggerContext) LogManager.


Video Answer


1 Answers

If you set an external configuration file and set its watch to true you can indeed change the logging configuration without restarting the application:

Watch

If this flag is specified and set to true then the framework will watch the configuration file and will reload the config each time the file is modified.

from the configuration page

There are some other ways to do it, namely you can change the configuration through code but why would you want to do that since you can as well change the configuration file. In the end, implementing other ways than the config file to change logging at runtime isn't very effective, so don't bother :)

like image 104
samy Avatar answered Oct 10 '22 09:10

samy