Windows 服务:在哪里写入日志消息(事件日志、文件或数据库表)/从 Web 访问

发布于 2024-09-15 16:54:18 字数 292 浏览 2 评论 0原文

我们有一个 Windows 服务(在 .NET 中),它将向日志写入大量消息。

该日志不仅对服务器管理员感兴趣,而且对使用网页访问系统的普通客户端也感兴趣。或者我们尝试远程调试系统!

我们正在考虑使用普通的 Windows 服务器事件日志,或者写入数据库表,或者可能只是老式写入文件。

有人有关于使用的最佳实践建议吗?

重要的是实际上只有日志可以在网页中查看,出于什么目的,我认为数据库表是实现此目的的最简单方法?通过网络显示 Windows 事件日志有多容易(假设我们只过滤与我们的应用程序相关的消息?)

We have a windows service (in .NET) that will write a fair amount of messages to a log.

This log is of interest not only to server administrators but also to normal clients who use a web page to access the system. Or to us trying to remote debug the system!

We are considering using the normal windows server event log, or writing to a Database table or maybe just old-skool writing to a file.

Does anyone have any best practise advice on which to use?

Important is really only that the log is available to view in the web page, for which purpose I imagine the DB table being the easiest method to accomplish this? How easy would it be to show the windows event log via the web (assuming we only filter for messages which are relevant to our app?)

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

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

发布评论

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

评论(4

混吃等死 2024-09-22 16:54:18

正如您所说,日志需要通过网页访问,存储信息的最佳位置几乎肯定是在数据库中,因为您可以使用您熟悉的代码来检索记录以在网络中呈现界面。

也就是说,如果您正在构建“企业”系统,您可能需要考虑监控解决方案,例如 Big Brother 具有内置功能来监视事件日志条目并对其做出反应,因此在这种情况下,以某种形式记录到事件日志对于系统管理员来说非常有价值。此外,Windows 还提供“事件日志转发 ”,它允许聚合来自多台计算机的事件日志条目,以便在一台计算机上进行审查。可能与您的场景无关,但值得记住。

As you've stated that the log needs to be accessible via a web page, the best place to store the information would almost certainly be in the database as you can use code that you're familiar with to retrieve records to present in the web interface.

That said, if you're building an "enterprise" system, you might want to consider the fact that monitoring solutions such as Big Brother have facilities built in to watch for event log entries and react to them, so some form of logging to the Event Log would be valuable for system administrators in that situation. Also, Windows offers "Event Log Forwarding" which allows event log entries from multiple machines to be aggregated for review on a single machine. Possibly not relevant in your scenario, but worth bearing in mind.

小耗子 2024-09-22 16:54:18

尝试考虑实施的难易程度。您已经拥有使用数据库的整个基础设施。添加新的存储过程或查询应该很容易。您可以轻松进行备份。而且,如果需要,您可以轻松地将此数据库转移到另一台服务器。
Windows 服务器事件日志也是一个好地方,但备份、可移植性和性能可能会受到影响。
如果您有专用的数据库服务器,那么这是一个更好的选择,恕我直言

Try to think about ease of implementing. You already have the whole infrastructure to work with DB. It should be easy to just add new stored procedure or query. You can easy have a backup. And also, you can easy transfer this DB to another server if you need.
Windows server event log is a good place too, but backups, portability and performance can suffer.
If you have a dedicated DB server then it is a better choice, IMHO

伤痕我心 2024-09-22 16:54:18

如果您使用诸如企业库日志记录之类的东西,那么将一条消息记录到多个位置就非常简单了。扩展它并编写您自己的格式和目标也很容易。您甚至可以使用它退出进程日志记录。另一个好处是,如果其中一个位置损坏(例如数据库关闭或文件被锁定),您将拥有记录这些错误的事件日志。

另请注意,您的本地事件查看器可以 连接到另一台计算机。管理员通常不会在授予开发人员读取权限方面遇到问题。事件查看器的另一个优点是,如果您使用 LogParser,则可以查询它。

If you use something like Enterprise Library logging its pretty trivial to have one message get logged to multiple locations. It also pretty easy to extend it and write your own formats and targets. You can even get out of process logging with it. Another nice aspect of this is that if one of the locations is broken (e.g. DB is down or the file is locked) you have the event log that will log those errors.

Also it should be noted that your local event viewer can Connect to another Computer. Administrators usually don't have a problem granting devs read access to it. Another plus to event viewer is that if you use LogParser you can query it.

栖迟 2024-09-22 16:54:18

Eventlog 是一个更好的日志记录位置。
您可以在事件查看器中查看日志记录并以编程方式访问这些记录。

我不建议你使用普通文件。这很简单,但不易管理。

Eventlog is a better place for logging.
You can view log records in Event Viewer and access these records programmatically.

I don't advise you to use an ordinary file. It's simple but not manageable.

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