Hello,
I've written a windows service that I am trying to get to write out to a custom log. In the partial class, it tests for and (I thought) should create a registration to the custom log:
public partial class ScriptTrigger : ServiceBase
{
public ScriptTrigger()
{
InitializeComponent();
if (!EventLog.SourceExists("ScriptTrigger"))
{
EventLog.CreateEventSource("ScriptTrigger", "ScriptTrigger");
CESourceed = true;
}
eventLog1.Source = "ScriptTrigger";
eventLog1.Log = "ScriptTrigger";
}
But, when I try to start the service I get a message saying the service has started then stopped. I've attached the debugger, and I find out that the first attempt to write to the custom log (in OnStart) is failing with this message:
"The source 'ScriptTrigger' is not registered in log 'ScriptTrigger'. (It is registered in log 'Application'). The Source and Log properties must be matched, or you may set Log to the empty string, and it will automatically be matched to the Source property."
I've tried to delete the source using this code:
static void Main(string[] args)
{
if (System.Diagnostics.EventLog.SourceExists("ScriptTrigger"))
{
EventLog.DeleteEventSource("ScriptTrigger");
}
else
{
Console.WriteLine("No ScriptTrigger Source Exists");
}
if (System.Diagnostics.EventLog.Exists("ScriptTrigger"))
{
EventLog.Delete("ScriptTrigger");
}
else
{
Console.WriteLine("No ScriptTrigger Log Exists");
}
But it returns a SecurityException error saying the source was not found and the only inaccessable log is Security.
Can someone give me a clue as to what I'm doing wrong here?
Thanks in advance!!