将事件日志组织到文件夹中

发布于 2024-11-15 19:54:05 字数 316 浏览 2 评论 0原文

我想要创建多个服务,并且希望它们将每个服务记录在我指定的同一目录/文件夹下的日志条目中,这样当我打开 Windows 事件查看器时,我可以看到它们全部放置在一个文件夹中。例如,service1 将登录到 service1_log,service2 将登录到 service2_log,并且 service1_log 和 service2_log 都将驻留在名为 Myservices 的文件夹中。 我在 Windows 事件日志 API 或任何其他 API 中没有找到任何适合此问题的内容。我可以在 Windows 事件查看器中看到有文件夹,但我只能在日志层次结构的根目录中创建日志。

提前致谢 托马斯

I want to create multiple services and I want them to log each in a log entry under the same directory/folder that I specify so when I open Windows Event Viewer I can see them all placed in one folder. For example service1 would log into service1_log, service2 would log into service2_log and both service1_log and service2_log would reside in one folder named Myservices.
I haven't found anything in Windows Event Log API or any other API that would fit into this problem..I can see in windows event viewer there are folders but I can only create logs into the root of the logs hierarchy there.

Thanks in advance
Tomas

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

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

发布评论

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

评论(2

寄与心 2024-11-22 19:54:05

Windows 事件日志不登录目录。但是,事件日志分为多个日志(应用程序系统安全等),这些日志在事件查看器中显示为文件夹。您可以创建自己的日志,该日志将在应用程序和服务日志中显示为单独的文件夹(假设是 Windows Vista 或更高版本),方法是调用 EventLog.CreateEventSource

但是,我不会建议您创建自己的日志。相反,您可以让您的服务记录到应用程序日志中。通过让每个服务使用单独的事件源,您可以轻松过滤应用程序日志,仅显示感兴趣的日志消息。再次假设 Windows Vista 或更高版本,您可以在自定义视图节点下创建自定义视图并按源过滤它。然后,此文件夹将仅显示来自您的服务的日志消息。


快进五年:现在,使用 EventSource 类,允许您为 < 创建事件一个href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb968803(v=vs.85).aspx" rel="nofollow">Windows 事件跟踪 (ETW)。 ETW 是高度可配置的,具有非常好的性能,但最初使用起来也有点困难。消息大小有限,安装新清单需要管理权限,而诊断等通道正在收集您无法查看日志等的数据。但总而言之,ETW 是记录到 em>应用程序事件日志。

Windows Event Log does not log into directories. However, the event log is split into several logs (Application, System, Security etc.) that are presented as folders in Event Viewer. You can create your own log that will appear as a separate folder in Applications and Services Logs (assuming Windows Vista or later) by calling EventLog.CreateEventSource.

However, I will not recommend that you create your own log. Instead you can let your services log to the Application log. By letting each service use a separate event source you can easily filter the Application log to only only display the interesting log messages. Again assuming Windows Vista or later you can create a custom view below the Custom Views node and filter it by source. This folder will then only show log messages from your services.


Fast forward five years: Now, it is quite easy to create you own log that can be seen in Application and Services Logs by using the EventSource class which allows you to create events for Event Tracing for Windows (ETW). ETW is highly configurable, has very good performance but can also be a bit difficult to use initially. Message size is limited, installing a new manifest requires administrative rights, while channels like Diagnostics are collecting data you can't view the log etc. But all in all ETW is a good alternative to logging to the Application event log.

鹿! 2024-11-22 19:54:05

长话短说,使用 .NET 4 框架并不容易完成这一任务。看起来 .NET 4.5 对此提供了更好的支持,但并不是非常简单。您可以将它们放入每个应用程序的文件夹中,但将这些文件夹放入公共文件夹中会复杂得多。

请参阅另一个线程上的以下答案:
https://stackoverflow.com/a/10528920/848419

Long story short, it is not easily accomplished using the .NET 4 framework. It looks like .NET 4.5 offers better support for this, but is is not terribly simple. You can put them into folders per application, but putting those folders in a common folder would be a lot more complex.

See the following answser on another thread:
https://stackoverflow.com/a/10528920/848419

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