简体   繁体   English

我应该在哪里存储错误日志?

[英]Where should I store error logs?

I'm building a C#/Asp.Net (FW 2.0) web application and I was wondering where I should store my error logs entry. 我正在构建一个C#/ Asp.Net(FW 2.0)Web应用程序,我想知道我应该在哪里存储我的错误日志条目。

I could write it on a file on the server, but that doesn't seems right to me. 我可以把它写在服务器上的文件中,但这对我来说似乎不对。 It would be insconsistent with the idea of a database . 这与数据库的想法是不一致的。

The other obivous answer is on the database, but what happened if I do not have any connection with the database. 另一个重要的答案是在数据库上,但如果我没有与数据库有任何连接会发生什么。 If the client get a connection error to the database what do I do(because the server and the database aren't on the same machine obviously)? 如果客户端收到数据库连接错误我该怎么办(因为服务器和数据库显然不在同一台机器上)?

Your suggestions are appreciated. 您的建议表示赞赏。

Than you 比你

Edit : I'm talking about basic error logging here, please do not refer such things as big frameworks like log4net. 编辑:我在这里谈论基本的错误记录,请不要像log4net这样的大框架。

System Event log with appropriate event source (logging channel) 具有适当事件源的系统事件日志(日志记录通道)

http://support.microsoft.com/kb/307024 http://support.microsoft.com/kb/307024

Compared to logging to a DB log4net or nlog are not "big frameworks". 与记录到数据库相比,log4net或nlog不是“大框架”。 Keep it simple and these two provide exactly what you need, with very little ramp up period. 保持简单,这两个提供你所需要的,只有很少的加速期。

Having a fallback mechanism is a very valid scenario. 拥有回退机制是一个非常有效的方案。 Logging to the windows event log is often not practical, because it isn't easy to analyze to logs, as is with relational databases. 记录到Windows事件日志通常是不切实际的,因为与关系数据库一样,分析日志并不容易。 But allowing events to be logged to the event log when your database fails is not a luxury option IMO. 但是,当数据库发生故障时,允许将事件记录到事件日志中并不是IMO的奢侈选择。

This scenario is one of the reasons I built a logging framework (I won't reference it, just as you requested). 这种情况是我构建日志框架的原因之一(我不会像您的请求那样引用它)。 It supports a concept called 'fallbackProvider' that allow the event to be logged to an alternative logger in case the main logger fails. 它支持一个名为'fallbackProvider'的概念,允许在主记录器失败的情况下将事件记录到备用记录器。 When you write your own logging mechanism, you could embrace such a concept. 当您编写自己的日志记录机制时,您可以接受这样的概念。

Good luck. 祝好运。

Store it in the event log; 将其存储在事件日志中; it is designed for this purpose after all! 它毕竟是为此目的而设计的! Its the place most people would look for errors, messages and warning regardless of what they know about the application. 无论他们对应用程序了解多少,大多数人都会寻找错误,消息和警告。

The enterprise library provides a framework for logging which you can use Enterprise Library . 企业库提供了一个可以使用Enterprise Library的日志记录框架。 This allows you to change how/where events are logged based on a configuration file so you don't have to make a decision where events are logged. 这允许您根据配置文件更改事件的记录方式/位置,这样您就不必决定记录事件的位置。

In addition to this, if you use the exception handling block you can also log errors to the eventlog with minimal effort 除此之外,如果使用异常处理块,您还可以轻松地将错误记录到事件日志中

I guess you really have three options: 我想你真的有三种选择:

  1. Use a small database to store all the error logs on the local machine using something light-weight like SQLlite or SQLServer Compact. 使用小型数据库使用像SQLlite或SQLServer Compact这样轻量级的东西在本地计算机上存储所有错误日志。
  2. Save it to a flat file (xml, or what have you) where you can view it. 将其保存到您可以查看的平面文件(xml或您拥有的文件)中。
  3. Send it straight to the Event Log. 直接发送到事件日志。 (I'd probably do this). (我可能会这样做)。

记录到数据库和xml作为后备,asp.net帐户将需要perms将错误记录到事件查看器,这可能不是一个好主意在Web服务器,除非它绝对是成功的。

If you're willing to consider a simple commercial product, take a look at Gibraltar . 如果您愿意考虑一个简单的商业产品,请看看直布罗陀 It stores logs locally then uploads them to a web service when a connection is available. 它在本地存储日志,然后在连接可用时将其上载到Web服务。 The logs are then indexed in an embedded database and an analysis tool lets you review errors and other information at whatever level of detail you require. 然后在嵌入式数据库中对日志进行索引,并使用分析工具查看所需的任何详细级别的错误和其他信息。

I see that you're a student, Frank. 弗兰克,我看到你是学生。 Email me directly to discuss the possibility of us offering you a free license. 直接给我发电子邮件,讨论我们为您提供免费许可的可能性。

-System Event Viewer - 系统事件查看器
-you may cache your error to local & lightweight db file (can be SqLite/Sql Compact), then when connection is available, you send it to server - 你可以将你的错误缓存到本地和轻量级db文件(可以是SqLite / Sql Compact),然后当连接可用时,将它发送到服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM