2013-01-31 113 views
1

下面是我用来初始化事件日志的代码,下面是我用来写入日志的示例代码行。WCF服务不写入事件日志

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); 

但是,该程序目前没有按照指示写入日志。没有任何类型的消息正在写入。任何人都可以看到上面的代码有什么问题,或者提供关于在哪里寻找问题的建议?

回答

3

是的,sLog应该是您想在事件查看器中写入的日志类型。例如,Application会将其写入Windows日志下的应用程序日志。

编辑: 您可能没有创建事件源的权限。 尝试添加该键,您的注册表: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\YourSourceNameHere]

另外,如果你没有运行你的应用程序作为管理员,尝试这样做也是如此。

+0

我将字符串声明更改为以下内容:'private string sLog =“Application”;'它仍然没有写入日志。 – NealR

+0

编辑答案,希望这会有所帮助 – Artless

+0

您是正确的,Web服务没有列在应用程序文件夹下。源代码是否与代码中的名称相同? (在这种情况下:“达芬奇”) – NealR