更改日志级别而不重新启动应用程序
Changing log level without restarting application
可以在不重新启动 ASP.NET 应用程序的情况下更改 log4net 日志记录级别。配置 log4net 配置的一些可能方法是:
- ASP.NET 网络配置文件。
- 添加单独的配置文件并在 AssemblyInfo.cs 文件中引用配置文件:
[assembly:log4net.Config.XmlConfigurator(ConfigFile="Log4Net.config",Watch=true)]
更改 web.config 文件中的配置将重新启动应用程序。如果我不想重新启动应用程序,是否建议使用单独的配置文件,或者有什么不同的方法吗?
如果您设置外部配置文件并将其监视设置为 true,您确实可以在不重新启动应用程序的情况下更改日志记录配置:
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.
还有其他一些方法可以做到这一点,即您可以通过代码更改配置,但您为什么要这样做,因为您也可以更改配置文件。最后,实现配置文件以外的其他方式来在运行时更改日志记录并不是很有效,所以不要打扰:)
可以在不重新启动 ASP.NET 应用程序的情况下更改 log4net 日志记录级别。配置 log4net 配置的一些可能方法是:
- ASP.NET 网络配置文件。
- 添加单独的配置文件并在 AssemblyInfo.cs 文件中引用配置文件:
[assembly:log4net.Config.XmlConfigurator(ConfigFile="Log4Net.config",Watch=true)]
更改 web.config 文件中的配置将重新启动应用程序。如果我不想重新启动应用程序,是否建议使用单独的配置文件,或者有什么不同的方法吗?
如果您设置外部配置文件并将其监视设置为 true,您确实可以在不重新启动应用程序的情况下更改日志记录配置:
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.
还有其他一些方法可以做到这一点,即您可以通过代码更改配置,但您为什么要这样做,因为您也可以更改配置文件。最后,实现配置文件以外的其他方式来在运行时更改日志记录并不是很有效,所以不要打扰:)