When I use the following code to write to Application Event log, everything works fine:
EventLog log = new EventLog();
log.Source = "Application";
log.WriteEntry("test message", EventLogEntryType.Error);
When I use the code that is from MSDN and all other blogs, I get the security error (I am guessing because CreateEventSource raises it).
string sSource = "MyWebService";
string sLog = "myApplication";
string sMsg = errorMessage;
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
EventLog.WriteEntry(sSource, sMsg, EventLogEntryType.Error);
So, do I need to check whether the source exists if all I need is to write to Application log which is there by default?
What is the proper way to write to EventViewer?