事件日志:SQL 或不 SQL

发布于 2024-12-28 09:44:53 字数 515 浏览 0 评论 0原文

我正在构建一个 Web 应用程序,它将从多个服务器提取事件日志并将其显示到我设置的页面中。我已将其设置为返回应用程序日志和系统日志的 20 个事件。但是,我正在尝试决定是否要将数据保存到 SQL 数据库并从那里显示它或直接从服务器显示到列表框中。我倾向于直接使用列表框,因为数据变化如此频繁。有人对以其他方式这样做有什么建议或好处吗?

以防万一有人好奇,这是我正在使用的代码:

string LogType = "Application";
string serverIP = "192.168.1.5";
EventLog eventLog = new EventLog(LogType, serverIP);
int LastLog = eventLog.Entries.Count;
int i;

for (i = eventLog.Entries.Count - 1; i >= LastLog - 20; i--) {
    EventLogEntry CurrentEntry = eventLog.Entries[i];
}

I am building a web application that will pull event logs from multiple servers and display them into a page that I have set up. I have set it to go back 20 events for both the Application log and the System log. However, I am trying to decide if I want to save the data to a SQL database and display it from there or directly from the server into a list box. I was leaning towards directly to the list box just because the data changes so frequently. Does anyone have any suggestions or benefits from doing this any other way?

Just in case anyone is curious, here is the code I am using:

string LogType = "Application";
string serverIP = "192.168.1.5";
EventLog eventLog = new EventLog(LogType, serverIP);
int LastLog = eventLog.Entries.Count;
int i;

for (i = eventLog.Entries.Count - 1; i >= LastLog - 20; i--) {
    EventLogEntry CurrentEntry = eventLog.Entries[i];
}

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

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

发布评论

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

评论(1

一身仙ぐ女味 2025-01-04 09:44:53

实际上我没有看到将日志保存到数据库有任何好处。如果您计划服务来自应用程序的大量请求,您应该考虑将它们缓存在您的服务器中(我会尝试在内存中而不是数据库中进行),并不时刷新此缓存。即使您的服务器处理很少的请求 - 缓存事件也可能很有用,只是为了不过多地访问目标服务器。

由于这些数据(事件)在我看来本质上是不稳定的,并且可以随时轻松地重新生成(通过查询目标机器),并且经常更改 - 无需持久化它。

I actually don't see any benefits to save the logs to the database. If you're planning to serve a lot of requests from your application, you should consider caching them in your server (and I would try to do it in memory, and not in DB), and refreshing this cache from time to time. Even if your server handles few requests - it could be useful to cache the events, just for not hitting the target servers too much.

Since this data (events) seem to me a volatile in nature, and can be easily regenerated (by querying the target machines) at any time, and changes frequently - there is no need to persist it.

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