Reputation: 541
I'm trying to write to the application event log. The following code executes without error under Windows 8 (when run with admin privileges), but I don't see any events showing up when looking at the Application log in the Windows Event Viewer. Can anyone help me figure out what I'm doing wrong. Do I need to add something to app.config?
using System.Diagnostics;
namespace tracetest2
{
class Program
{
static void Main(string[] args)
{
if (!EventLog.SourceExists("TestSource"))
{
EventLog.CreateEventSource("TestSource", "Application");
}
EventLog appLog = new EventLog("Application", ".", "TestSource");
appLog.EnableRaisingEvents = true;
appLog.EndInit();
Debug.WriteLine(appLog.Entries.Count);
appLog.WriteEntry("An entry to the Application event log.");
Debug.WriteLine(appLog.Entries.Count);
}
}
}
Upvotes: 5
Views: 2741
Reputation: 4003
According to the Microsoft website, we have the following information:
Note: 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.
The machine must be restarted every time you create a new custom event key. (Or just restart the EventViewer service) :)
Upvotes: 3