启用/禁用生产环境中的企业库日志记录

发布于 2024-10-18 16:46:43 字数 157 浏览 2 评论 0原文

在我的生产中,我不想有严重性为“详细”(或“调试”)的日志条目。我只需要信息、错误等。启用和禁用日志记录(调试条目)的正确方法是什么?

我做了一些研究,一种可能性是使用自定义过滤器类来启用和禁用严重性为“详细”的所有日志。但是,在生产环境中部署应用程序时,启用和禁用的正确方法是什么?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光清浅 2024-10-25 16:46:44

您不必进入自定义过滤器。假设您定义了一个类别,那么您只需设置

在配置中,这看起来像:

<categorySources>
    <add switchValue="Information" name="General">
        <listeners>
            <add name="Formatted EventLog TraceListener" />
        </listeners>
    </add>
</categorySources>

就最佳实践而言,没有一种正确的方法。通常,您可能会启用记录尽可能少的信息以正确支持应用程序。这将取决于您在应用程序中放置的日志记录类型。对于大多数应用程序来说,这可能是信息警告。然而,其他因素可能会影响这一点,包括当前应用程序的稳定性、操作要求等。

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:

<categorySources>
    <add switchValue="Information" name="General">
        <listeners>
            <add name="Formatted EventLog TraceListener" />
        </listeners>
    </add>
</categorySources>

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 or Warning. However, other factors could influence this including current application stability, operational requirements etc.

给妤﹃绝世温柔 2024-10-25 16:46:44

您可以在配置文件中设置日志记录级别,这样,如果您出于某种原因在生产中需要它,您可以随时将其打开。

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.

那支青花 2024-10-25 16:46:44

您可以在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文