Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF服务未写入事件日志_C#_Wcf_Event Log - Fatal编程技术网

C# WCF服务未写入事件日志

C# WCF服务未写入事件日志,c#,wcf,event-log,C#,Wcf,Event 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.W

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

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

然而,程序当前并没有按照指令写入日志。没有任何类型的消息被写入。任何人都可以看到上面的代码有什么问题,或者就在哪里查找问题提供任何建议吗

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

编辑: 您可能没有创建事件源的权限。 尝试将此项添加到注册表:
[HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\YourSourceName here]


另外,如果您不是以管理员身份运行应用程序,也可以尝试这样做。

我将字符串声明更改为:“private string sLog=“Application”;”并且它仍然没有写入日志。编辑了答案,希望这将帮助您确认正确,web服务未列在应用程序文件夹下。源名称是否与代码中的名称相同?(在本例中为“达芬奇”)