[英]Service written in C# fails when writing to new event log source
Given the following code 给出以下代码
InitializeComponent();
try
{
if (!System.Diagnostics.EventLog.SourceExists(this.ServiceName))
{
System.Diagnostics.EventLog.CreateEventSource(
this.ServiceName, "ProfileWatcherLog");
}
profileWatcherLog.Source = this.ServiceName;
profileWatcherLog.Log = "ProfileWatcherLog";
}
catch (Exception e)
{
profileWatcherLog.WriteEntry(String.Format("ERROR: {0}",e.Message));
}
finally
{
profileWatcherLog.WriteEntry("Profile Watcher setup");
}
If I use an already existing event log source it works fine, but if I try the event source I want to use for this application then it fails. 如果我使用一个已经存在的事件日志源,则可以正常工作,但是,如果我尝试了要用于此应用程序的事件源,则它将失败。
I have even tried the following; 我什至尝试了以下方法; which uses the properties of the profileWatcherLog and the ServiceName and it still fails.
它使用profileWatcherLog和ServiceName的属性,但仍然失败。
if (!System.Diagnostics.EventLog.SourceExists(this.ServiceName))
{
System.Diagnostics.EventLog.CreateEventSource(
this.ServiceName, profileWatcherLog.Log);
}
profileWatcherLog.Source = this.ServiceName;
Anyone see what I have done wrong? 有人看到我做错了吗?
Thanks in advance 提前致谢
You only have to restart your computer. 您只需要重新启动计算机即可。
If a source has already been mapped to a log and you remap it to a new log, you must restart the computer for the changes to take effect.
如果源已映射到日志,然后将其重新映射到新日志,则必须重新启动计算机以使更改生效。
https://msdn.microsoft.com/en-us/library/2awhba7a.aspx https://msdn.microsoft.com/en-us/library/2awhba7a.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.