Log4net:如何在运行时启用调试日志记录? [英] Log4net: How to enable debug logging at runtime?

查看:492
本文介绍了Log4net:如何在运行时启用调试日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在测试环境中,启用了调试日志,因此我可以看到详细的调试日志消息.在生产环境中,我希望默认情况下禁用调试日志,但仍然需要在需要时启用/禁用它.

In the test environment, the debug log is enabled, so I can see detailed debug log messages. In production environment, I want to disable debug log by default, but still want to enable/disable it if needed.

是否可以在运行时启用调试日志而无需重新启动应用程序?我的日志记录代码如下所示:

Can I enable debug log at runtime without restarting my application? My logging code looks like below:

if(logger.IsDebugEnabled) Logger.Debug("debug message");

推荐答案

您可以通过设置日志级别来更改日志级别,然后应用新设置:

You can change to loglevel by setting it and then apply the new settings:

((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level = Level.Debug;
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).RaiseConfigurationChanged(EventArgs.Empty);

这篇关于Log4net:如何在运行时启用调试日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆