记录 ASP.NET 中的异常
在我的团队中,有关于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不要重新发明轮子 - 使用现有的日志库/工具,例如 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.
另一个很棒且易于使用的 Logging-Library 是 NLOG
来自该站点:
“支持的目标包括:
自动文件命名和归档
– 将您的日志存储在数据库中
由 .NET
TCP、UDP、SOAP、MSMQ 协议
消息的颜色编码
随时可以收到电子邮件
应用程序错误发生
...以及更多
其他关键功能:
Another great and easy to use Logging-Library is NLOG
From the site:
"Supported targets include:
automatic file naming and archival
– store your logs in databases
supported by .NET
TCP, UDP, SOAP, MSMQ protocols
color coding of messages
can receive emails whenever
application errors occur
… and many more
Other key features:
我更喜欢文本文件,因为它具有更大的灵活性和更轻松的导航。我认为这是一个偏好问题,但 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.
在我工作的应用程序中,我们习惯于在数据库中记录每个异常,因此这种方式更容易将异常详细信息链接到要求他们填写的“用户错误报告”(位于我们的默认错误页面)。它帮助我们进行统计,并且如前所述,将异常详细信息链接到错误的用户描述(例如,他采取了哪些步骤来获得该错误,等等......)
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...)
免责声明:我是 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)