网站日志(IIS7,托管)
我有一个托管在 webhost4life 的 ASP.NET MVC 应用程序
保存日志的好方法是什么?
我可以访问我上传网站的 ftp,我应该有效地做
File.AppendAllText("log.txt", "Ooops, we have an error" + e.Message);
还是有更好的方法?发送电子邮件?将日志保存到数据库中?
I have an ASP.NET MVC app hosted at webhost4life
What's a good way to save logs?
I have an access to the ftp I upload site to, should I just do effectively
File.AppendAllText("log.txt", "Ooops, we have an error" + e.Message);
Or is there a better way? Send e-mail? save log into a database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我总是尝试登录数据库并在数据库无法访问时退回到文件(也许这就是异常的原因)。这使您可以直接针对日志运行查询和报告,并立即找出问题所在。您还可以通过存储关键异常并对其进行标记等来对应用程序运行“健康检查”。
I always try to log to a database and fall back on a file if the database is inaccessible (perhaps that's the cause of the exception). This allows you to run queries and reporting against the log directly and find out what the problem is immediately. You can also run a "health check" against the application by storing critical excepions and marking them, etc.
避免写入文件系统;这可能会在尝试写入同一文件的线程之间产生冲突/竞争条件。数据库是解决这个问题的绝佳解决方案,并提供了一些很好的好处,例如能够从标准化数据轻松生成报告。
另外,您正在记录什么样的信息? IIS日志非常详细。保存这些日志中已有的信息会重复工作(服务器写入其日志,然后您编写自己的日志),这当然会导致性能下降。
Avoid writing to the file system; this can generate collisions/race conditions between threads that are attempting to write to the same file. Databases are wonderful solutions for this problem, and provide some nice benefits such as being able to generate reports easily from normalized data.
Also, what sort of information are you logging? The IIS logs are very detailed. Saving information that is already available in those logs duplicates work (the server writes its logs, and then you write your own), which of course incurs a performance hit.