登录到文件还是数据库更好? [英] Is it better to log to file or database?

查看:115
本文介绍了登录到文件还是数据库更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们仍在使用旧的Classic ASP,并且希望在用户在我们的应用程序中执行某些操作时进行记录.我们将编写一个通用子例程以接受我们想要记录的详细信息.

We're still using old Classic ASP and are wanting to log whenever a user does something in our application. We'll write a generic subroutine to take in the details we want to log.

我们应该使用FileSystemObject将此日志记录为一个txt文件还是将其记录到MSSQL数据库中?

Should we log this to say a txt file using FileSystemObject or log it to a MSSQL database?

如果是数据库,我们应该在现有数据库中添加一个新表还是使用单独的数据库?

If the database, should we add a new table to the one existing database or should we use a separate database?

推荐答案

编辑

事后看来,更好的答案是先登录到两个文件系统,然后再登录到集中式数据库(即使延迟).

In hindsight, a better answer is to log to BOTH file system (first, immediately) and then to a centralized database (even if delayed).

写入文件系统的基本原理是,如果外部基础结构依赖性(例如网络,数据库或安全性问题)使您无法进行远程写入,则至少可以进行回退,前提是可以从Web服务器的硬盘中恢复数据(类似于航空业中的黑匣子.

The rationale behind writing to file system that if an external infrastructure dependency like network, database, or security issue prevents you from writing remotely, that at least you have a fall back if you can recover data from the web server's hard disk (something akin to a black box in the airline industry).

实际上,可以将企业日志管理器(例如 Splunk )配置为抓取本地服务器日志文件(例如,由log4net,EntLib Logging Application Block等编写),然后将它们集中在可搜索的数据库中,在该数据库中可以对记录的数据进行挖掘,图形化,显示在仪表板上等.

In fact, enterprise log managers like Splunk can be configured to scrape your local server log files (e.g. as written by log4net, the EntLib Logging Application Block, et al) and then centralize them in a searchable database, where data logged can be mined, graphed, shown on dashboards, etc.

但是从操作角度来看,很可能您将拥有一个Web服务器场,并且假设本地文件系统和远程数据库日志记录机制都在正常工作,则99%的用例实际上是试图查找任何内容日志文件中的内容仍将通过中央数据库(理想情况下是具有不错的前端系统,以便您可以查询,汇总甚至绘制日志数据).

But from an operational perspective, where it is likely that you will have a farm of web servers, and assuming that both the local file system and remote database logging mechanisms are working, the 99% use case for actually trying to find anything in a log file will still be via the central database (ideally with a decent front end system to allow you to query, aggregate and even graph the log data).

原始答案

如果您有数据库,我建议使用它作为审核记录,而不是文件系统.

If you have the database in place, I would recommend using this for audit records instead of the filesystem.

理论价格:

  • 数据类型化和归一化分类(severity, action type, user, date ...)
  • 与Grep相比,查找审计数据(select ... from Audits where ...)更容易
  • 清理起来更容易(例如Delete from Audits where = Date ...)
  • 备份更容易
  • typed and normalized classification of data (severity, action type, user, date ...)
  • it is easier to find audit data (select ... from Audits where ...) vs Grep
  • it is easier to clean up (e.g. Delete from Audits where = Date ...)
  • it is easier to back up

使用现有数据库还是使用新数据库的决定取决于-如果您有多个应用程序(具有自己的数据库),并且想要集中记录/审核所有应用程序中的所有操作,那么集中式数据库可能很有意义.

The decision to use existing db or new one depends - if you have multiple applications (with their own databases) and want to log / audit all actions in all apps centrally, then a centralized db might make sense.

由于您说过要审核用户活动,因此在与用户表/定义(如果适用)相同的数据库中进行审核可能很有意义.

Since you say you want to audit user activity, it may would make sense to audit in the same db as your users table / definition (if applicable).

这篇关于登录到文件还是数据库更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆