记录 ASP.NET 中的异常

发布于 2024-10-25 18:34:26 字数 113 浏览 7 评论 0原文

在我的团队中,有关于 Web 应用程序异常日志记录的讨论,讨论我们是否应该记录到文本文件或事件日志。

谁能告诉我应用程序中发生的异常日志记录的更好方法是什么?我已经提到的两者之一还是有更好的选择?

In my team there is discussion about web application exception logging, regarding whether we should log to a text file or the event log.

Can anyone please tell me which is the better way of exception logging occuring in the application? Either one of the two I've already mentioned or is there a better option?

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

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

发布评论

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

评论(5

情话墙 2024-11-01 18:34:26

不要重新发明轮子 - 使用现有的日志库/工具,例如 log4net< /a> 或 ELMAH 而不是编写自己的日志库。两者都为您提供了记录异常的多种选择,这取决于您的喜好。

需要考虑两件事:

1 - 如果您正在登录数据库,但数据库不可用/负载过重,您会登录到哪里?
2 - Windows 事件日志记录非常轻量级,事件日志转发意味着您可以自动聚合来自多台计算机的日志而无需编写任何代码

Don't reinvent the wheel - use an already existing logging library/tool such as log4net or ELMAH instead of writing your own logging library. Both give you multiple choices for where you log exceptions to, it's up to you which you prefer.

Two things to consider:

1 - Where do you log to if you're logging to the database, but the database is unavailable / under heavy load?
2 - Windows Event Logging is very light-weight and event log forwarding means you can automagically aggregate logs from multiple machines without writing any code.

一张白纸 2024-11-01 18:34:26

另一个很棒且易于使用的 Logging-Library 是 NLOG

来自该站点:

“支持的目标包括:

  • 文件 – 单个文件或多个,与
    自动文件命名和归档
  • 事件日志 - 本地或远程
  • 数据库
    – 将您的日志存储在数据库中
    由 .NET
  • 网络支持 – 使用
    TCP、UDP、SOAP、MSMQ 协议
  • 命令行控制台 – 包括
    消息的颜色编码
  • 电子邮件 – 您
    随时可以收到电子邮件
    应用程序错误发生
  • ASP.NET 跟踪

...以及更多

其他关键功能:

  • 非常容易配置,通过配置文件和以编程方式
  • 易于使用的记录器模式(从 log4xxx 得知)
  • 高级路由使用缓冲、异步日志记录、负载平衡、故障转移和更多
  • 跨平台支持:.NET Framework、.NET Compact Framework 和 Mono(在 Windows 和 Unix 上)”

Another great and easy to use Logging-Library is NLOG

From the site:

"Supported targets include:

  • Files – single file or multiple, with
    automatic file naming and archival
  • Event Log – local or remote
  • Database
    – store your logs in databases
    supported by .NET
  • Network – using
    TCP, UDP, SOAP, MSMQ protocols
  • Command-line console – including
    color coding of messages
  • E-mail – you
    can receive emails whenever
    application errors occur
  • ASP.NET trace

… and many more

Other key features:

  • very easy to configure, both through configuration file and programmatically
  • easy-to-use logger pattern known from log4xxx
  • advanced routing using buffering, asynchronous logging, load balancing, failover, and more
  • cross-platform support: .NET Framework, .NET Compact Framework and Mono (on Windows and Unix)"
时光无声 2024-11-01 18:34:26

我更喜欢文本文件,因为它具有更大的灵活性和更轻松的导航。我认为这是一个偏好问题,但 Windows 事件日志中的错误之间的导航似乎非常麻烦。除了繁琐的导航之外,它还包含您不关心的错误。如果您可以定义格式和内容,那么效率会更高。

I prefer a text file because it allows for more flexibility and easier navigation. I suppose it's a matter of preference, but the navigation between errors in the Windows event log seems very cumbersome. In addition to the cumbersome navigation it includes errors that you don't care about. If you can define the format and the content then it's much more efficient.

如梦亦如幻 2024-11-01 18:34:26

在我工作的应用程序中,我们习惯于在数据库中记录每个异常,因此这种方式更容易将异常详细信息链接到要求他们填写的“用户错误报告”(位于我们的默认错误页面)。它帮助我们进行统计,并且如前所述,将异常详细信息链接到错误的用户描述(例如,他采取了哪些步骤来获得该错误,等等......)

At the app I work, we are used to log every exception at the database, so this way is easier to link the exceptions details to the "user error report" they are requested to fill (which is at our the default error page). It helps us on statistics and as already said, linking exception details to the user description of the error (like, which steps he took to get that error, etc...)

瘫痪情歌 2024-11-01 18:34:26

免责声明:我是 KissLog.net 日志应用程序的开发人员。

log4Net 和 Elmah 非常好,但它们的能力有限。

Elmah 不支持跟踪/日志消息,并且仅记录异常,并且 log4Net 不提供用于浏览日志的用户界面。

您可以尝试使用 KissLog.net,这是一个应用程序,我尝试聚合所有必要的日志记录功能(捕获错误,日志/跟踪消息,易于使用的用户界面)

Disclaimer: i am the developer of KissLog.net logging application.

log4Net and Elmah are very good, but they have limited capabilities.

Elmah doesn't support trace / log messages, and logs only the exceptions, and log4Net doesn't provide a user interface to navigate through the logs.

You can try to use KissLog.net, it is an application where i tried to aggregate all the necessary logging features (capture errors, log / trace messages, easy to use user-interface)

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