c# - 在没有事件源注册的情况下写入 Windows 应用程序事件日志

标签 c# .net windows logging event-log

有没有办法写入这个事件日志:

enter image description here

或者至少,一些其他 Windows 默认日志,我不必在其中注册事件源

最佳答案

是的,有一种方法可以写入您正在寻找的事件日志。您不需要创建新的源,只需使用现有的源,它通常与事件日志的名称同名,而且在某些情况下,例如事件日志应用程序,无需管理权限即可访问*。

*其他无法直接访问的情况,例如安全事件日志,它只能由操作系统访问。

我使用此代码直接写入事件日志应用程序:

using (EventLog eventLog = new EventLog("Application")) 
{
    eventLog.Source = "Application"; 
    eventLog.WriteEntry("Log message example", EventLogEntryType.Information, 101, 1); 
}

如您所见,EventLog 源与 EventLog 的名称相同。其原因可在 Event Sources @ Windows Dev Center 中找到。 (我将引用来源名称的部分加粗):

Each log in the Eventlog key contains subkeys called event sources. The event source is the name of the software that logs the event. It is often the name of the application or the name of a subcomponent of the application if the application is large. You can add a maximum of 16,384 event sources to the registry.

关于c# - 在没有事件源注册的情况下写入 Windows 应用程序事件日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25725151/

相关文章:

java - 无法在 Windows 8 上更改 java 版本

c - 如何用C/C++实现键盘缓冲窗口无阻塞

c# - 客户端不读取远程 MSMQ 队列,但可以发送到远程队列

c# - 使用资源管理器部署和rest api获取Azure VM

c# - Dotnet Core 是否实现组合根发现?

c# - Azure 表随机返回 null 值

c# - 编译时的类型或命名空间定义或文件结尾预期问题

即使被杀死和处置(在 Linux 上),C# 启动进程也会泄漏内存

.net - 检查 session 项是否存在,自身失败,对象引用未设置错误

windows - 使用 Delphi 查找特殊驱动器