启用/禁用生产环境中的企业库日志记录
在我的生产中,我不想有严重性为“详细”(或“调试”)的日志条目。我只需要信息、错误等。启用和禁用日志记录(调试条目)的正确方法是什么?
我做了一些研究,一种可能性是使用自定义过滤器类来启用和禁用严重性为“详细”的所有日志。但是,在生产环境中部署应用程序时,启用和禁用的正确方法是什么?
On my production, I don't want to have log entry with severity Verbose (or Debug). I need only the info, error etc. What is the right method to enable and disable logging (the debug entries)?
I did some research and one possibility is to use Custom Filter class to enable and disable all logs with severity "verbose". But When deploying application on production, what is the right way to enable and disable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不必进入自定义过滤器。假设您定义了一个类别,那么您只需设置
在配置中,这看起来像:
就最佳实践而言,没有一种正确的方法。通常,您可能会启用记录尽可能少的信息以正确支持应用程序。这将取决于您在应用程序中放置的日志记录类型。对于大多数应用程序来说,这可能是
信息
或警告
。然而,其他因素可能会影响这一点,包括当前应用程序的稳定性、操作要求等。You don't have to get in to custom filters. Assuming you have one category defined then you just need to set the Severity or SourceLevel that you want to log. It sounds like you want to set the SourceLevel to
Information
which "allows Critical, Error, Warning, and Information events through".In config this would look something like:
In terms of best practices there is no one right way. Usually you would probably enable the logging of as little information as required to properly support the application. This will depend on the type of logging you've placed in your application. For most applications this would probably be
Information
orWarning
. However, other factors could influence this including current application stability, operational requirements etc.您可以在配置文件中设置日志记录级别,这样,如果您出于某种原因在生产中需要它,您可以随时将其打开。
You can set your logging level in your config file, that way, should you need it in production for whatever reason, you can switch it on at any time.
您可以在 web.config.release 和 web.config.debug 文件中设置不同的级别。您可以在此处阅读更多信息。
You can set different levels in web.config.release and web.config.debug files. You can read more here.