写入Windows应用程序事件日志中没有注册的事件源 [英] Write to Windows Application Event Log without registering an Event Source

查看:474
本文介绍了写入Windows应用程序事件日志中没有注册的事件源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法写入此事件日志:

Is there a way to write to this event log:

或者至少,其他一些Windows默认的日志,在那里我没有注册事件源?

Or at least, some other Windows default log, where I don't have to register an event source?

推荐答案

确实是这样,它存在的方式写信给你要找的事件日志。所以,你不需要创建一个新的来源,只是简单地使用存在的,它往往具有相同的名称作为事件日志的名字,并在某些情况下,如事件日志应用程序,可以入店没有管理权限* 。

Yes indeed, it exists a way to write to the eventlog you were looking for. So, you don't need to create a new source, just simply use the existent, which often has the same name as the EventLog's name and also, in some cases like the event log "Application", can be accesible without administrative privileges*.

*其他情况下,如果你不能直接访问它,是安全日志为例,它仅由操作系统访问。

*Other cases, where you cannot access it directly, are the Security EventLog for example, which is only accessed by the operating system.

我用这个code直接写入到应用程序事件日志:

I used this code to write directly to the "Application" event log:



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

正如你所看到的,事件日志的源名称是一样的EvenLog本身。这样做的原因可以在该链路中找到(Ⅰ粗体其指源名的部分):

As you can see, the EventLog's source name is the same as the EvenLog itself. The reason of this can be found in this link (I bolded the part which refers to source name):

<一个href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa363661(v=vs.85).aspx">http://msdn.microsoft.com/en-us/library/windows/desktop/aa363661(v=vs.85).aspx

每个日志中的事件日志项包含子项叫做事件源。事件源是记录该事件的软件的名称。 这通常是应用程序或应用程序的子组件,如果应用程序是大名的名称。您最多16,384事件源可以添加到注册表中。

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.

它回答你的问题。

这篇关于写入Windows应用程序事件日志中没有注册的事件源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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