简体   繁体   English

在事件查看器中写入应用程序日志

[英]Writing to Application Log in Event Viewer

After 3 hours of getting this message "The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security." 收到此消息3小时后“找不到源,但无法搜索部分或全部事件日志。无法访问日志:安全性。”

and trying several solutions, I am posting here. 并尝试了几种解决方案,我在这里发帖。 Is there a concise way to write to an event log from the WebService (asmx) running on my localhost? 是否有一种简洁的方法从我的localhost上运行的WebService(asmx)写入事件日志?

I followed the instructions found on msdn and added NETWORK SERVICE using regedit, giving it read rights as per http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/416098a4-4183-4711-a53b-e10966c9801d/ 我按照msdn上的说明进行了操作,并使用regedit添加了NETWORK SERVICE,根据http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/416098a4-4183-4711-a53b-给出了读取权限。 e10966c9801d /

Here is my code inside my Web Service 这是我的Web服务中的代码

    string sSource = "MyWebService";
    string sLog = "Application";
    string sEvent = "Sample Event";            

    if (!EventLog.SourceExists(sSource))
        EventLog.CreateEventSource(sSource, sLog);

    EventLog.WriteEntry(sSource, sEvent);
    EventLog.WriteEntry(sSource, sEvent,
        EventLogEntryType.Error, 234);

The windows account that your web service runs as (might be Network Service or something completely different, depending on configuration) needs to have the "Manage auditing and security log" right in order to be able to create new event log sources. 您的Web服务运行的Windows帐户(可能是网络服务或完全不同的东西,具体取决于配置)需要具有“管理审核和安全日志”权限才能创建新的事件日志源。 You can assign this right in Local Security Policy > Local Policies > User Rights Assignment. 您可以在本地安全策略>本地策略>用户权限分配中分配此权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM