简体   繁体   English

WCF服务不写入事件日志

[英]WCF Service not writing to Event Log

Below is the code I use to initialize the event log, and below that is a sample line of code I use to write to the log. 下面是我用来初始化事件日志的代码,下面是我用来写入日志的代码示例。

private string sSource = "DaVinci";
private string sLog = "WCF WebService";

//Initialize Event Log
if(!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog);

//Write openining message
EventLog.WriteEntry(sSource, "Opening WCF Service", EventLogEntryType.Warning);

The program, however, is not currently writing to the log, as it's instructed to do. 但是,该程序当前没有写入日志,因为它已被指示执行。 No messages of any kind are being written. 没有任何类型的消息被写入。 Can anyone either see what is wrong with the above code or offer any suggestions as to where to look for the problem? 任何人都可以看到上面的代码有什么问题或提供任何关于在哪里寻找问题的建议?

Yes, sLog should be the type of log you want to write to in the event viewer. 是的,sLog应该是您要在事件查看器中写入的日志类型。 For instance, Application will write it to the Application log under Windows Logs. 例如, Application会将其写入Windows Logs下的Application日志。

EDIT: It is possible you do not have permission to create the event source. 编辑:您可能无权创建事件源。 Try adding this key to your registry: [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\YourSourceNameHere] 尝试将此密钥添加到您的注册表: [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\YourSourceNameHere]

Also, if you are not running your app as Administrator, try doing so as well. 此外,如果您没有以管理员身份运行应用程序,请尝试这样做。

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

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