清理追踪

发布于 2024-11-16 07:03:49 字数 335 浏览 2 评论 0原文

我有一个使用 NLog 进行跟踪的 C# 大型应用程序(> 50k loc),并且跟踪已经有些失控。一些库支持适当的跟踪(正确的级别/详细程度),其他库只是将所有内容发送到错误/信息级别。

我需要清理它,以便使所有错误反映正确的严重性。因此,当我真的想重新启用一般异常跟踪以跟踪生产问题时,我们基本上禁用了生产跟踪。

解决这个问题的良好工作流程是什么?是否有任何工具可以帮助以干净的方式跟踪所有跟踪语句?我目前计划使用 re Sharper 并找到所有用法,然后花一些时间来解决这个问题。

更新:我在这里不清楚,我正在寻找一些关于一般跟踪的良好指南,也许还有一些关于重组我的大型代码库的最佳方法的建议。

I have a large application (>50k loc) in C# using NLog for tracing, and the tracing has gotten somewhat out of control. Some libraries embrace proper tracing (correct level / verbosity), others just send everything to Error/Info level.

I need to clean this up in order to make all errors reflect the correct severity. As a result we have essentially disabled production tracing, when I really want to reenable general exception tracing to keep track of production problems.

What is a good workflow for tacking this? Are there any tools to help track down all trace statements in a clean fashion? I am currently planning to use re sharper and find all usages, and just spend some time tackling this.

Update: I wasn't clear here, I am looking for some good guidelines on tracing in general, and perhaps some suggestions on the best way to retool my large code base.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

坚持沉默 2024-11-23 07:03:49

这就是我使用的(但我使用 log4net,但我猜它是一样的)

.trace() - 用于记录诸如函数进入和退出之类的内容,以及巨大的数据转储

for(a in l) { trace("List contents: "+ a) }

。 debug() - 是在考虑分支时打印 1(一)行完整的信息。
您可以在单个函数中包含多个调试语句,但不能有 1 个 pr 行。
当您阅读调试语句时,它应该读起来像
的简洁版本
功能。

.debug("Checking if current account {} for user {} has more than {} amount", amount);
.debug("Account criteria met for account {} for user {}; making withdrawel of {}", otheramount);
.debug("Account {} debited by {} amount. Transaction key {}");

每个调试行都必须独立,并包含理解它所需的所有信息。只写一行“检查帐户级别”是没有用的,因为您的下一个问题将是哪个帐户?什么用户?多少?

.info() - 最多 1 或两个 pr 函数,并且仅在高级范围内。数据一定要完整。

.info("Withdrawel procecss complete for account {}, user {}, for amount {}");

.warn() - 非严重错误,数据完整,因此您可以将这些传递给邮件记录器,并偶尔检查该邮箱。

.error() - 与警告相同,但更重要。用户被主动阻止实现其目标,因此您需要更频繁地查看这些内容。

.fatal() - 如果可能的话,应直接转到 sysadm 的寻呼机,并提供有关服务器/计算机名称的信息。

除此之外,确保每个类都有自己的基于该类的记录器,这样即使在运行时,您也可以轻松地打开和关闭代码特定区域的日志。

This is what I use (but I use log4net, but I guess its the same)

.trace() - is to be used to record stuff like function entry and exits, and huge datadumps

for(a in l) { trace("List contents: "+ a) }

.debug() - is to print 1 (one) line of information complete when considering a branch.
You may have several debug statements in a single function, but not 1 pr line.
When you read the debug statements, it should read like a terse version of the
function.

.debug("Checking if current account {} for user {} has more than {} amount", amount);
.debug("Account criteria met for account {} for user {}; making withdrawel of {}", otheramount);
.debug("Account {} debited by {} amount. Transaction key {}");

Every debug line must stand alone, and contain all information required to understand it. Its no good having a line just read "Checking account level", because your next question will be which account? what user? what amount?

.info() - At most 1 or two pr function, and only in the high level scope. Must be data complete.

.info("Withdrawel procecss complete for account {}, user {}, for amount {}");

.warn() - Non critical errors, data complete, so you can pass these to a mailer logger, and check that mailbox once in a while.

.error() - same as warn, but more important. User was actively blocked from achieving his goal, so you want to review those more often.

.fatal() - Should go directly to pager of sysadm, if possible with information about server/machine name.

Aside from this, make sure each class has its own logger, based on that class, so you can easily turn logs on and off for specific areas of the code, even at runtime.

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