It is possible to change log4net logging level without restart ASP.NET application. Some possible ways to configure log4net configuration are:
[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?
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)
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.
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 :)
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