Skip to content

Commit

Permalink
Fix broken EventLog initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
iasmanis committed Oct 18, 2017
1 parent b672608 commit 0f688f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion NotakeyBGService/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ internal void Run()
);
});

EventLog.WriteEntry("Application", "Notakey BG Service [com.notakey.cp.bgs]: Service started successfully", EventLogEntryType.Information, 94);
EventLog.WriteEntry(EntryPoint.LogApplication, "Service started successfully", EventLogEntryType.Information, 94);

SpawnServer();
}
Expand Down
20 changes: 12 additions & 8 deletions NotakeyBGService/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ static class EntryPoint
static ManualResetEvent terminationEvent = new ManualResetEvent(false);

private static string BaseRegistryKey = "Software\\Notakey\\WindowsCP";


public static string LogSource = "Application";
public static string LogApplication = "Notakey BG Service";

/// <summary>
/// The main entry point for the application.
/// </summary>
Expand All @@ -33,12 +34,15 @@ static void Main(string[] args)
ApiConfiguration.AccessId = args[1];
}

if (!EventLog.SourceExists(LogSource))
EventLog.CreateEventSource(LogSource, LogApplication);

LoadRegistryConfigOverrrides();

if(String.IsNullOrEmpty(ApiConfiguration.ApiEndpoint) || String.IsNullOrEmpty(ApiConfiguration.AccessId))
{
Console.WriteLine("Missing configuration for: 1. ApiEndpoint and/or 2. AccessId");
EventLog.WriteEntry("Application", "Notakey BG Service [com.notakey.cp.bgs]: Missing configuration for ApiEndpoint and/or AccessId", EventLogEntryType.Error);
EventLog.WriteEntry(LogApplication, "Missing configuration for ApiEndpoint and/or AccessId", EventLogEntryType.Error);

return;
}
Expand All @@ -48,7 +52,7 @@ static void Main(string[] args)

terminationEvent.WaitOne();
Console.WriteLine("Received termination event. Quitting ...");
EventLog.WriteEntry("Application", "Notakey BG Service [com.notakey.cp.bgs]: Service is stopping", EventLogEntryType.Information);
EventLog.WriteEntry(LogApplication, "Service is stopping", EventLogEntryType.Information);
app.Cleanup();
}

Expand All @@ -65,7 +69,7 @@ static void LoadRegistryConfigOverrrides()
if (registryNode == null)
{
Console.WriteLine("No registry configuration overrides provided...");
EventLog.WriteEntry("Application", "Notakey BG Service [com.notakey.cp.bgs]: No registry information avaialble in key [" + BaseRegistryKey + "]", EventLogEntryType.Information, 99);
EventLog.WriteEntry(LogApplication, "No registry information avaialble in key [" + BaseRegistryKey + "]", EventLogEntryType.Information, 99);
return;
}

Expand Down Expand Up @@ -115,7 +119,7 @@ static void LoadRegistryConfigOverrrides()
ApiConfiguration.AuthCreateTimeoutSecs = (int)ttl;
if(ApiConfiguration.AuthCreateTimeoutSecs > 100)
{
EventLog.WriteEntry("Application", "Notakey BG Service [com.notakey.cp.bgs]: AuthCreateTimeoutSecs value of "+ ApiConfiguration.AuthCreateTimeoutSecs + " over enforced limit of 100 seconds", EventLogEntryType.Warning, 98);
EventLog.WriteEntry(LogApplication, "AuthCreateTimeoutSecs value of "+ ApiConfiguration.AuthCreateTimeoutSecs + " over enforced limit of 100 seconds", EventLogEntryType.Warning, 98);
}
}

Expand All @@ -127,7 +131,7 @@ static void LoadRegistryConfigOverrrides()
ApiConfiguration.AuthWaitTimeoutSecs = (int)ttl;
if (ApiConfiguration.AuthWaitTimeoutSecs > 100)
{
EventLog.WriteEntry("Application", "Notakey BG Service [com.notakey.cp.bgs]: AuthWaitTimeoutSecs value of " + ApiConfiguration.AuthWaitTimeoutSecs + " over enforced limit of 100 seconds", EventLogEntryType.Warning, 97);
EventLog.WriteEntry(LogApplication, "AuthWaitTimeoutSecs value of " + ApiConfiguration.AuthWaitTimeoutSecs + " over enforced limit of 100 seconds", EventLogEntryType.Warning, 97);
}
}

Expand All @@ -142,7 +146,7 @@ static void LoadRegistryConfigOverrrides()
ApiConfiguration.HealthTimeoutSecs = (int)ttl;
if (ApiConfiguration.HealthTimeoutSecs > 100)
{
EventLog.WriteEntry("Application", "Notakey BG Service [com.notakey.cp.bgs]: HealthTimeoutSecs value of " + ApiConfiguration.HealthTimeoutSecs + " over enforced limit of 100 seconds", EventLogEntryType.Warning, 96);
EventLog.WriteEntry(LogApplication, "HealthTimeoutSecs value of " + ApiConfiguration.HealthTimeoutSecs + " over enforced limit of 100 seconds", EventLogEntryType.Warning, 96);
}
}
}
Expand Down

0 comments on commit 0f688f5

Please sign in to comment.